Skip to content

Commit f0f082b

Browse files
chore: add batch test
1 parent cf37b85 commit f0f082b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/store/tests/batch.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { Store } from '../src/store'
3+
import { batch } from '../src'
4+
5+
describe('batch', () => {
6+
test('updates store immediately', () => {
7+
const store = new Store({ hello: 100, world: 200 })
8+
batch(() => {
9+
store.setState((state) => ({ ...state, hello: state.hello + 1 }))
10+
expect(store.state.hello).toBe(101)
11+
expect(store.state.world).toBe(200)
12+
store.setState((state) => ({ ...state, world: state.world + 1 }))
13+
expect(store.state.hello).toBe(101)
14+
expect(store.state.world).toBe(201)
15+
})
16+
17+
expect(store.state.hello).toBe(101)
18+
expect(store.state.world).toBe(201)
19+
})
20+
})

0 commit comments

Comments
 (0)