Skip to content

Commit

Permalink
fix(MemoryMovexStore.spec): 🐛 add resolve() so await functions correc…
Browse files Browse the repository at this point in the history
…tly after each store operation
  • Loading branch information
GabrielCTroia committed Nov 5, 2023
1 parent 16fe963 commit 27f0d76
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions libs/movex/src/lib/movex-store/MemoryMovexStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,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({});
});
});}
});

0 comments on commit 27f0d76

Please sign in to comment.