test(vanilla/subscribe): add test for covering fireImmediately option in 'subscribeWithSelector' (#3131)

This commit is contained in:
Wonsuk Choi 2025-05-22 12:58:34 +09:00 committed by GitHub
parent 01749b01c7
commit a03acc3887
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,4 +120,15 @@ describe('subscribe()', () => {
expect(spy2).toHaveBeenCalledTimes(1)
expect(spy2).toHaveBeenCalledWith(1, 0)
})
it('should call listener immediately when fireImmediately is true', () => {
const spy = vi.fn()
const initialState = { value: 1 }
const { subscribe } = createStore(subscribeWithSelector(() => initialState))
subscribe((s) => s.value, spy, { fireImmediately: true })
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith(1, 1)
})
})