Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add observation for Dexie users #75

Open
hyphenized opened this issue Oct 13, 2022 · 3 comments
Open

Add observation for Dexie users #75

hyphenized opened this issue Oct 13, 2022 · 3 comments

Comments

@hyphenized
Copy link

When using Dexie.js, it caches the global indexedDB variable, so resetting the db state won't work as expected. An easy fix is to manually handle each constructor call to explicitly use a new instance of fakeIndexedDB or add a getter to override the value in your test setup like this:

Object.defineProperty(Dexie.dependencies, "indexedDB", {
  get: () => indexedDB,
})

So far I've tracked this back to 3.0.3 which is the version we're currently using.

@dumbmatter
Copy link
Owner

Another solution would be to add some non-standard functions to indexedDB that would be useful in testing. Like indexedDB.reset() could delete all the object stores. And other stuff like #50 and #51.

@JJosephttg
Copy link

That works, but I agree, we should have an easier way of doing this! I also had a type error with the 'auto' import in my Angular Jasmine project. It was complaining that indexedDB can't be assigned and that it is a getter on window. I managed to get passed that typeerror by doing Object.defineProperty(window, 'indexedDB', { value: indexedDb, writable: true }); BEFORE the import from auto happens. although in retrospect you may or may not need the writable true part, and maybe this solution should also be included in the auto logic as a part of this library

@dumbmatter
Copy link
Owner

@JJosephttg do you have an example repo that is showing an error for the auto import? I was not aware of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants