@@ -64,28 +64,28 @@ const useTheme = (initialTheme) => {
6464}
6565
6666// useTheme.test.js
67- import { useHook , cleanup } from ' react-hooks-testing-library'
67+ import { testHook , cleanup , act } from ' react-hooks-testing-library'
6868
6969describe (' custom hook tests' , () => {
7070 afterEach (cleanup)
7171
7272 test (' should use theme' , () => {
73- const { getCurrentValue } = useHook (() => useTheme (' light' ))
73+ const { result } = testHook (() => useTheme (' light' ))
7474
75- const theme = getCurrentValue ()
75+ const theme = result . current
7676
7777 expect (theme .primaryLight ).toBe (' #FFFFFF' )
7878 expect (theme .primaryDark ).toBe (' #000000' )
7979 })
8080
8181 test (' should update theme' , () => {
82- const { getCurrentValue , act } = useHook (() => useTheme (' light' ))
82+ const { result } = testHook (() => useTheme (' light' ))
8383
84- const { toggleTheme } = getCurrentValue ()
84+ const { toggleTheme } = result . current
8585
8686 act (() => toggleTheme ())
8787
88- const theme = getCurrentValue ()
88+ const theme = result . current
8989
9090 expect (theme .primaryLight ).toBe (' #000000' )
9191 expect (theme .primaryDark ).toBe (' #FFFFFF' )
@@ -97,11 +97,13 @@ describe('custom hook tests', () => {
9797 dark: { primaryLight: ' #CCBBAA' , primaryDark: ' #AABBCC' }
9898 }
9999
100- const { getCurrentValue , addContextProvider } = useHook (() => useTheme (' light' ))
100+ const wrapper = ({ children }) => (
101+ < ThemesContext .Provider value= {customThemes}> {children}< / ThemesContext .Provider >
102+ )
101103
102- addContextProvider (ThemesContext , { value : customThemes })
104+ const { result } = testHook (() => useTheme ( ' light ' ) , { wrapper })
103105
104- const theme = getCurrentValue ()
106+ const theme = result . current
105107
106108 expect (theme .primaryLight ).toBe (' #AABBCC' )
107109 expect (theme .primaryDark ).toBe (' #CCBBAA' )
0 commit comments