October 2019
Intermediate to advanced
426 pages
11h 49m
English
Using the act function from the React Hooks Testing Library, we can execute functions from the Hook and then check the new result.
Let's now test actions of our Counter Hook:
test('should increment counter', () => { const { result } = renderHook(() => useCounter())
act(() => result.current.increment())
expect(result.current.count).toBe(1)})
As we can see, we can simply use the act function to trigger actions in our Hook and then test the value just like we did before.
Read now
Unlock full access