From 7d5dc95088417c344068bdaf4a00905fdaf62f09 Mon Sep 17 00:00:00 2001 From: "Gabriel C. Troia" Date: Sun, 5 Nov 2023 14:18:26 -0600 Subject: [PATCH] fix(MemoryMovexStore.spec): :bug: add resolve() so await functions correctly after each store operation --- .../lib/movex-store/MemoryMovexStore.spec.ts | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/libs/movex/src/lib/movex-store/MemoryMovexStore.spec.ts b/libs/movex/src/lib/movex-store/MemoryMovexStore.spec.ts index 2780f319..7669b465 100644 --- a/libs/movex/src/lib/movex-store/MemoryMovexStore.spec.ts +++ b/libs/movex/src/lib/movex-store/MemoryMovexStore.spec.ts @@ -104,40 +104,53 @@ describe('Concurrency', () => { describe('clearAll functionality', () => { test('clearAll with an empty store', async () => { const store = new MemoryMovexStore<{ counter: () => { count: number } }>(); - await store.clearAll(); + await store.clearAll().resolve(); + expect(store.all()).toEqual({}); }); test('newly created items are not there after clearAll', async () => { const store = new MemoryMovexStore<{ counter: () => { count: number } }>(); - await store.create('counter:1', { count: 1 }); - await store.clearAll(); + + await store.create('counter:1', { count: 1 }).resolve(); + await store.clearAll().resolve(); + expect(store.all()).toEqual({}); }); test('clearAll after items are updated', async () => { const store = new MemoryMovexStore<{ counter: () => { count: number } }>(); - await store.create('counter:1', { count: 1 }); - await store.updateState('counter:1', (prev) => ({ count: prev.count + 1 })); - await store.clearAll(); + + await store.create('counter:1', { count: 1 }).resolve(); + await store + .updateState('counter:1', (prev) => ({ count: prev.count + 1 })) + .resolve(); + await store.clearAll().resolve(); + expect(store.all()).toEqual({}); }); test('clearAll after items are removed', async () => { const store = new MemoryMovexStore<{ counter: () => { count: number } }>(); - await store.create('counter:1', { count: 1 }); - await store.remove('counter:1'); - await store.clearAll(); + + await store.create('counter:1', { count: 1 }).resolve(); + await store.remove('counter:1').resolve(); + await store.clearAll().resolve(); + expect(store.all()).toEqual({}); }); test('clearAll after multiple operations', async () => { const store = new MemoryMovexStore<{ counter: () => { count: number } }>(); - await store.create('counter:1', { count: 1 }); - await store.updateState('counter:1', (prev) => ({ count: prev.count + 1 })); - await store.remove('counter:1'); - await store.create('counter:2', { count: 2 }); - await store.clearAll(); + + await store.create('counter:1', { count: 1 }).resolve(); + await store + .updateState('counter:1', (prev) => ({ count: prev.count + 1 })) + .resolve(); + await store.remove('counter:1').resolve(); + await store.create('counter:2', { count: 2 }).resolve(); + await store.clearAll().resolve(); + expect(store.all()).toEqual({}); }); -});} \ No newline at end of file +});