@@ -13,39 +13,37 @@ describe('custom hook tests', () => {
13
13
const useTheme = ( initialTheme ) => {
14
14
const themes = useContext ( ThemesContext )
15
15
const [ theme , setTheme ] = useState ( initialTheme )
16
- const changeTheme = ( ) => {
16
+ const toggleTheme = ( ) => {
17
17
setTheme ( theme === 'light' ? 'dark' : 'light' )
18
18
}
19
- return useMemo ( ( ) => ( { ...themes [ theme ] , changeTheme } ) , [ theme ] )
19
+ return useMemo ( ( ) => ( { ...themes [ theme ] , toggleTheme } ) , [ theme ] )
20
20
}
21
21
22
22
afterEach ( cleanup )
23
23
24
- test ( 'should get initial theme from custom hook ' , ( ) => {
24
+ test ( 'should use theme' , ( ) => {
25
25
const { result } = testHook ( ( ) => useTheme ( 'light' ) )
26
26
27
27
const theme = result . current
28
28
29
29
expect ( theme . primaryLight ) . toBe ( '#FFFFFF' )
30
30
expect ( theme . primaryDark ) . toBe ( '#000000' )
31
- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
32
31
} )
33
32
34
- test ( 'should update theme using custom hook ' , ( ) => {
33
+ test ( 'should update theme' , ( ) => {
35
34
const { result } = testHook ( ( ) => useTheme ( 'light' ) )
36
35
37
- const { changeTheme } = result . current
36
+ const { toggleTheme } = result . current
38
37
39
- act ( ( ) => changeTheme ( ) )
38
+ act ( ( ) => toggleTheme ( ) )
40
39
41
40
const theme = result . current
42
41
43
42
expect ( theme . primaryLight ) . toBe ( '#000000' )
44
43
expect ( theme . primaryDark ) . toBe ( '#FFFFFF' )
45
- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
46
44
} )
47
45
48
- test ( 'should get custom theme from custom hook ' , ( ) => {
46
+ test ( 'should use custom theme' , ( ) => {
49
47
const customThemes = {
50
48
light : { primaryLight : '#AABBCC' , primaryDark : '#CCBBAA' } ,
51
49
dark : { primaryLight : '#CCBBAA' , primaryDark : '#AABBCC' }
@@ -61,6 +59,5 @@ describe('custom hook tests', () => {
61
59
62
60
expect ( theme . primaryLight ) . toBe ( '#AABBCC' )
63
61
expect ( theme . primaryDark ) . toBe ( '#CCBBAA' )
64
- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
65
62
} )
66
63
} )
0 commit comments