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) + }) +})