Skip to content

Instantly share code, notes, and snippets.

@nemrosim
Created June 30, 2022 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemrosim/0167043837c1867048b7552534b78b11 to your computer and use it in GitHub Desktop.
Save nemrosim/0167043837c1867048b7552534b78b11 to your computer and use it in GitHub Desktop.
import { renderHook, act } from '@testing-library/react-hooks';
import { useSimplestHook } from './1.simplest-hook';
it('should set to true', () => {
const { result } = renderHook(() => useSimplestHook());
expect(result.current.isTrue).toBe(false);
act(() => {
result.current.toggle();
});
expect(result.current.isTrue).toBe(true);
});
it('should set to true after 1 second', async () => {
const { result, waitForNextUpdate } = renderHook(() => useSimplestHook());
expect(result.current.isTrue).toBe(false);
await waitForNextUpdate();
expect(result.current.isTrue).toBe(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment