re: How to write tests for a library that requires being run on the browser (like Dexie.js or localforage)? VIEW POST

FULL DISCUSSION
 

You can always mock those dependencies since those libraries should have been in theory tested before so you only need to test your logic. There's a lot of different ways you can do this, for example in Jest you can simply do in the top of your test:

jest.mock('localforage')

And it'll automatically mock every import that your code does of localforage so that instead of running the real library you can just mock the calls. You can read more here: jestjs.io/docs/en/mock-functions

I suppose Mocha has a similar approach too if you want to use it.

code of conduct - report abuse