Skip to content

Commit 63d1e81

Browse files
author
wulimaomao
committed
test: add test for setting state to null
1 parent 42ac8ee commit 63d1e81

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/vanilla/basic.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ it('can set the store without merging', () => {
112112
expect(getState()).toEqual({ b: 2 })
113113
})
114114

115+
it('can set the object store to null', () => {
116+
const { setState, getState } = createStore<{ a: number } | null>(() => ({
117+
a: 1,
118+
}))
119+
120+
setState(null)
121+
122+
expect(getState()).toEqual(null)
123+
})
124+
125+
it('can set the non-object store to null', () => {
126+
const { setState, getState } = createStore<string | null>(() => 'value')
127+
128+
setState(null)
129+
130+
expect(getState()).toEqual(null)
131+
})
132+
115133
it('works with non-object state', () => {
116134
const store = createStore<number>(() => 1)
117135
const inc = () => store.setState((c) => c + 1)

0 commit comments

Comments
 (0)