Skip to content

Commit 83fdeb8

Browse files
committed
adding test to ensure boolean values support
1 parent c303f81 commit 83fdeb8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/index.test.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ jest.mock('svelte')
88
function setupStore () {
99
function counter (store) {
1010
store.on('@init', () => {
11-
return { count: 0, foo: 'baz' }
11+
return { count: 0, foo: 'baz', loading: false }
1212
})
1313
store.on('inc', state => {
1414
return { count: state.count + 1 }
1515
})
16+
store.on('toggle', state => {
17+
return { loading: !state.loading }
18+
})
1619
}
1720

1821
return createStoreon([counter])
@@ -93,7 +96,7 @@ it('should not emit changes on other dispatches', () => {
9396
expect(countSpyCb).toHaveBeenCalledTimes(1)
9497
})
9598

96-
it('shoud to be unsubscribed', () => {
99+
it('should to be unsubscribed', () => {
97100
let currentValue
98101
let { count, dispatch } = useStoreon('count')
99102

@@ -111,3 +114,26 @@ it('shoud to be unsubscribed', () => {
111114

112115
expect(currentValue).toBe(1)
113116
})
117+
118+
it('should work with boolean values', () => {
119+
let currentValue
120+
let { loading, dispatch } = useStoreon('loading')
121+
122+
let unsubscribe = loading.subscribe(value => { currentValue = value })
123+
124+
expect(currentValue).toBe(false)
125+
126+
dispatch('toggle')
127+
128+
expect(currentValue).toBe(true)
129+
130+
dispatch('toggle')
131+
132+
expect(currentValue).toBe(false)
133+
134+
unsubscribe()
135+
136+
dispatch('toggle')
137+
138+
expect(currentValue).toBe(false)
139+
})

0 commit comments

Comments
 (0)