Skip to content

Commit

Permalink
test: add test for setting state to null
Browse files Browse the repository at this point in the history
  • Loading branch information
wulimaomao committed Nov 27, 2023
1 parent 42ac8ee commit 63d1e81
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/vanilla/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ it('can set the store without merging', () => {
expect(getState()).toEqual({ b: 2 })
})

it('can set the object store to null', () => {
const { setState, getState } = createStore<{ a: number } | null>(() => ({
a: 1,
}))

setState(null)

expect(getState()).toEqual(null)
})

it('can set the non-object store to null', () => {
const { setState, getState } = createStore<string | null>(() => 'value')

setState(null)

expect(getState()).toEqual(null)
})

it('works with non-object state', () => {
const store = createStore<number>(() => 1)
const inc = () => store.setState((c) => c + 1)
Expand Down

0 comments on commit 63d1e81

Please sign in to comment.