@@ -64,28 +64,28 @@ const useTheme = (initialTheme) => {
64
64
}
65
65
66
66
// useTheme.test.js
67
- import { useHook , cleanup } from ' react-hooks-testing-library'
67
+ import { testHook , cleanup , act } from ' react-hooks-testing-library'
68
68
69
69
describe (' custom hook tests' , () => {
70
70
afterEach (cleanup)
71
71
72
72
test (' should use theme' , () => {
73
- const { getCurrentValue } = useHook (() => useTheme (' light' ))
73
+ const { result } = testHook (() => useTheme (' light' ))
74
74
75
- const theme = getCurrentValue ()
75
+ const theme = result . current
76
76
77
77
expect (theme .primaryLight ).toBe (' #FFFFFF' )
78
78
expect (theme .primaryDark ).toBe (' #000000' )
79
79
})
80
80
81
81
test (' should update theme' , () => {
82
- const { getCurrentValue , act } = useHook (() => useTheme (' light' ))
82
+ const { result } = testHook (() => useTheme (' light' ))
83
83
84
- const { toggleTheme } = getCurrentValue ()
84
+ const { toggleTheme } = result . current
85
85
86
86
act (() => toggleTheme ())
87
87
88
- const theme = getCurrentValue ()
88
+ const theme = result . current
89
89
90
90
expect (theme .primaryLight ).toBe (' #000000' )
91
91
expect (theme .primaryDark ).toBe (' #FFFFFF' )
@@ -97,11 +97,13 @@ describe('custom hook tests', () => {
97
97
dark: { primaryLight: ' #CCBBAA' , primaryDark: ' #AABBCC' }
98
98
}
99
99
100
- const { getCurrentValue , addContextProvider } = useHook (() => useTheme (' light' ))
100
+ const wrapper = ({ children }) => (
101
+ < ThemesContext .Provider value= {customThemes}> {children}< / ThemesContext .Provider >
102
+ )
101
103
102
- addContextProvider (ThemesContext , { value : customThemes })
104
+ const { result } = testHook (() => useTheme ( ' light ' ) , { wrapper })
103
105
104
- const theme = getCurrentValue ()
106
+ const theme = result . current
105
107
106
108
expect (theme .primaryLight ).toBe (' #AABBCC' )
107
109
expect (theme .primaryDark ).toBe (' #CCBBAA' )
0 commit comments