-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.test.jsx
More file actions
35 lines (26 loc) · 895 Bytes
/
index.test.jsx
File metadata and controls
35 lines (26 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, it, beforeEach } from 'node:test';
import assert from 'node:assert/strict';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ThemeToggle from '../';
let mockCurrentTheme = 'light';
const toggleTheme = () => {
mockCurrentTheme = mockCurrentTheme === 'light' ? 'dark' : 'light';
};
describe('ThemeToggle', () => {
let toggle;
beforeEach(() => {
mockCurrentTheme = 'light';
render(<ThemeToggle onClick={toggleTheme} />);
toggle = screen.getByRole('button');
});
it('switches dark theme to light theme', async () => {
mockCurrentTheme = 'dark';
await userEvent.click(toggle);
assert.equal(mockCurrentTheme, 'light');
});
it('switches light theme to dark theme', async () => {
await userEvent.click(toggle);
assert.equal(mockCurrentTheme, 'dark');
});
});