11import { describe , it , expect , beforeAll } from 'vitest'
2- import { render , waitFor , screen } from '../src/tests/testing-library'
2+ import { render , waitFor } from '../src/tests/testing-library'
33import MatchMediaMock from '@/tests/mock-match-media'
44import { afterEach } from 'node:test'
55import { ThemeToggle } from '@/features/theme/components/theme-toggle'
6- import userEvent from '@testing-library/user-event '
6+ import { executeComponentTest } from '@/tests/test-component '
77
88describe ( 'when using the default system light theme' , ( ) => {
9- beforeAll ( ( ) => {
10- render ( < ThemeToggle /> )
11- } )
12-
13- it ( 'the theme is set to light' , async ( ) => {
14- await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'light' ) ) . toBe ( true ) )
9+ it ( 'the theme is set to light' , ( ) => {
10+ return executeComponentTest (
11+ ( ) => render ( < ThemeToggle /> ) ,
12+ async ( ) => {
13+ await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'light' ) ) . toBe ( true ) )
14+ }
15+ )
1516 } )
17+ } )
1618
17- describe ( 'when the theme is toggled to dark' , ( ) => {
18- it ( 'the theme is set to dark' , async ( ) => {
19- userEvent . click ( await screen . findByTestId ( 'theme-toggle-menu' ) )
20- userEvent . click ( await screen . findByText ( 'Dark' ) )
19+ describe ( 'when the theme is toggled to dark' , ( ) => {
20+ it ( 'the theme is set to dark' , async ( ) => {
21+ return executeComponentTest (
22+ ( ) => render ( < ThemeToggle /> ) ,
23+ async ( component , user ) => {
24+ user . click ( await component . findByTestId ( 'theme-toggle-menu' ) )
25+ user . click ( await component . findByText ( 'Dark' ) )
2126
22- await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'dark' ) ) . toBe ( true ) )
23- } )
27+ await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'dark' ) ) . toBe ( true ) )
28+ }
29+ )
2430 } )
2531} )
2632
@@ -30,11 +36,15 @@ describe('when using the default system dark theme', () => {
3036 beforeAll ( ( ) => {
3137 // Set system theme to dark
3238 matchMediaMock . useMediaQuery ( '(prefers-color-scheme: dark)' )
33- render ( < ThemeToggle /> )
3439 } )
3540 afterEach ( ( ) => matchMediaMock . clear ( ) )
3641
37- it ( 'the theme is set to dark' , async ( ) => {
38- await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'dark' ) ) . toBe ( true ) )
42+ it ( 'the theme is set to dark' , ( ) => {
43+ return executeComponentTest (
44+ ( ) => render ( < ThemeToggle /> ) ,
45+ async ( ) => {
46+ await waitFor ( ( ) => expect ( document . documentElement . classList . contains ( 'dark' ) ) . toBe ( true ) )
47+ }
48+ )
3949 } )
4050} )
0 commit comments