dumbmatter / fakeIndexedDB

A pure JS in-memory implementation of the IndexedDB API
Apache License 2.0
562 stars 69 forks source link

Correct way to refresh DB before each test #62

Closed J4CKVVH173 closed 3 years ago

J4CKVVH173 commented 3 years ago

I'm trying to refresh the DB before each test to have my tests completely isolated. I imported fake-indexeddb/auto in the top of test file and use beforeEach to call FDBFactory inside (like in README example). Is it a correct way to refresh db ?

import 'fake-indexeddb/auto';
import FDBFactory from 'fake-indexeddb/lib/FDBFactory';

beforeEach(() => {
  new FDBFactory();
});
dumbmatter commented 3 years ago

global.indexedDB = new FDBFactory(); is what you want, because all new FDBFactory(); does is create a new variable, which has no effect if you don't assign it to anything.

J4CKVVH173 commented 3 years ago

Thanks, it works