@@ -13,39 +13,37 @@ describe('custom hook tests', () => {
1313 const useTheme = ( initialTheme ) => {
1414 const themes = useContext ( ThemesContext )
1515 const [ theme , setTheme ] = useState ( initialTheme )
16- const changeTheme = ( ) => {
16+ const toggleTheme = ( ) => {
1717 setTheme ( theme === 'light' ? 'dark' : 'light' )
1818 }
19- return useMemo ( ( ) => ( { ...themes [ theme ] , changeTheme } ) , [ theme ] )
19+ return useMemo ( ( ) => ( { ...themes [ theme ] , toggleTheme } ) , [ theme ] )
2020 }
2121
2222 afterEach ( cleanup )
2323
24- test ( 'should get initial theme from custom hook ' , ( ) => {
24+ test ( 'should use theme' , ( ) => {
2525 const { result } = testHook ( ( ) => useTheme ( 'light' ) )
2626
2727 const theme = result . current
2828
2929 expect ( theme . primaryLight ) . toBe ( '#FFFFFF' )
3030 expect ( theme . primaryDark ) . toBe ( '#000000' )
31- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
3231 } )
3332
34- test ( 'should update theme using custom hook ' , ( ) => {
33+ test ( 'should update theme' , ( ) => {
3534 const { result } = testHook ( ( ) => useTheme ( 'light' ) )
3635
37- const { changeTheme } = result . current
36+ const { toggleTheme } = result . current
3837
39- act ( ( ) => changeTheme ( ) )
38+ act ( ( ) => toggleTheme ( ) )
4039
4140 const theme = result . current
4241
4342 expect ( theme . primaryLight ) . toBe ( '#000000' )
4443 expect ( theme . primaryDark ) . toBe ( '#FFFFFF' )
45- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
4644 } )
4745
48- test ( 'should get custom theme from custom hook ' , ( ) => {
46+ test ( 'should use custom theme' , ( ) => {
4947 const customThemes = {
5048 light : { primaryLight : '#AABBCC' , primaryDark : '#CCBBAA' } ,
5149 dark : { primaryLight : '#CCBBAA' , primaryDark : '#AABBCC' }
@@ -61,6 +59,5 @@ describe('custom hook tests', () => {
6159
6260 expect ( theme . primaryLight ) . toBe ( '#AABBCC' )
6361 expect ( theme . primaryDark ) . toBe ( '#CCBBAA' )
64- expect ( typeof theme . changeTheme ) . toBe ( 'function' )
6562 } )
6663} )
0 commit comments