Skip to content

Commit

Permalink
fixup! fixup! fixup! test(react): add simple cases
Browse files Browse the repository at this point in the history
  • Loading branch information
belozer committed Sep 22, 2019
1 parent 2fe8ef2 commit 0142144
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions packages/react/src/__tests__/index.tsx
Expand Up @@ -40,7 +40,6 @@ describe('@reatom/react', () => {
})

rerender()

expect(subscriber.mock.calls.length).toBe(1)
})

Expand Down Expand Up @@ -72,6 +71,29 @@ describe('@reatom/react', () => {
expect(result.current).toBe(30)
})

test('unsubscribe from prevent dynamic atom', () => {
const store = createStore(countAtom, { count: 10 });
const subscriber = jest.fn()
const _subscribe = store.subscribe
// @ts-ignore
store.subscribe = ((atom) => _subscribe(atom, subscriber))

const { rerender } = renderHook(({
multiplier
}) => useAtom(map(countAtom, count => count * multiplier)), {
initialProps: { multiplier: 2 },
wrapper: props => <Provider {...props} store={store} />
})

act(() => { store.dispatch(increment()) })
expect(subscriber.mock.calls.length).toBe(1)

rerender({ multiplier: 3 })

act(() => store.dispatch(increment()))
expect(subscriber.mock.calls.length).toBe(1)
})

test('does not update state if flag "isUpdatesNotNeeded" is set', () => {
const store = createStore(countAtom, { count: 10 });
const { result, rerender } = renderHook(({
Expand All @@ -91,10 +113,10 @@ describe('@reatom/react', () => {

test('unsubscribe from store after unmount', () => {
const store = createStore(null)
const baseSubscribe = store.subscribe
const _subscribe = store.subscribe
const subscriber = jest.fn()
// @ts-ignore
store.subscribe = ((atom) => baseSubscribe(atom, subscriber))
store.subscribe = ((atom) => _subscribe(atom, subscriber))

const { unmount } = renderHook(() => useAtom(countAtom, true), {
wrapper: props => <Provider {...props} store={store} />
Expand Down

0 comments on commit 0142144

Please sign in to comment.