From f0f082bba14ffaf68610f9d85ac158f2ec83c433 Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Fri, 16 May 2025 19:02:03 +0200 Subject: [PATCH] chore: add batch test --- packages/store/tests/batch.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/store/tests/batch.test.ts diff --git a/packages/store/tests/batch.test.ts b/packages/store/tests/batch.test.ts new file mode 100644 index 00000000..a08f64b3 --- /dev/null +++ b/packages/store/tests/batch.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, test } from 'vitest' +import { Store } from '../src/store' +import { batch } from '../src' + +describe('batch', () => { + test('updates store immediately', () => { + const store = new Store({ hello: 100, world: 200 }) + batch(() => { + store.setState((state) => ({ ...state, hello: state.hello + 1 })) + expect(store.state.hello).toBe(101) + expect(store.state.world).toBe(200) + store.setState((state) => ({ ...state, world: state.world + 1 })) + expect(store.state.hello).toBe(101) + expect(store.state.world).toBe(201) + }) + + expect(store.state.hello).toBe(101) + expect(store.state.world).toBe(201) + }) +})