aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-toggle/use-toggle.test.ts
blob: b2feeab0d0c0d922f38dcdb039d9faca42d75b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { describe, expect, it } from '@jest/globals';
import { act, renderHook } from '@testing-library/react';
import { useToggle } from './use-toggle';

describe('use-toggle', () => {
  it('returns the default state', () => {
    const { result } = renderHook(() => useToggle());

    expect(result.current[0]).toBe(false);
  });

  it('can switch the state', () => {
    const initialState = true;
    const { result } = renderHook(() => useToggle(initialState));

    expect(result.current[0]).toBe(initialState);

    act(() => {
      result.current[1]();
    });

    expect(result.current[0]).toBe(!initialState);
  });
});