diff --git a/src/Store.ts b/src/Store.ts index c3f7069..7a4fe35 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -65,8 +65,9 @@ export class Store< } reset(): void { - const schemaObjectTypes = resolveSchemaObjectTypes(this.schema) - this._collections = initializeCollections(schemaObjectTypes) + for (const collection of this._collections.values()) { + collection.clear() + } } protected createDocument( diff --git a/tests/reset.test.ts b/tests/reset.test.ts new file mode 100644 index 0000000..f9022e6 --- /dev/null +++ b/tests/reset.test.ts @@ -0,0 +1,23 @@ +import { Store } from '../src' +import { schema, TypesMap } from './fixtures' +import { postFactory, userFactory } from './utils/factories' +import { toCollection } from './utils' + +const store = new Store({ + schema, +}) + +afterEach(() => store.reset()) + +it('should clear all collections at once', () => { + toCollection(() => store.create('User', userFactory()), 5) + toCollection(() => store.create('Post', postFactory()), 5) + + expect(store.count('User')).toEqual(5) + expect(store.count('Post')).toEqual(5) + + store.reset() + + expect(store.count('User')).toEqual(0) + expect(store.count('Post')).toEqual(0) +})