use-page-headings-tree
Version:
A React hook to get tree data from a list of heading nodes
30 lines (22 loc) • 628 B
JavaScript
import { useMyHook } from './'
import { renderHook, act } from "@testing-library/react-hooks";
// mock timer using jest
jest.useFakeTimers();
describe('useMyHook', () => {
it('updates every second', () => {
const { result } = renderHook(() => useMyHook());
expect(result.current).toBe(0);
// Fast-forward 1sec
act(() => {
jest.advanceTimersByTime(1000);
});
// Check after total 1 sec
expect(result.current).toBe(1);
// Fast-forward 1 more sec
act(() => {
jest.advanceTimersByTime(1000);
});
// Check after total 2 sec
expect(result.current).toBe(2);
})
})