You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('should call the api and return response when status is idle',async()=>{queryReturn={status: 200,settings: TEST_SETTINGS};constinitialSettingsData={};const{ store, result, waitFor }=renderHookWithContext(()=>useSettings(),{initialState: {settings: {status: 'idle',data: initialSettingsData}},});expect(result.current.isUninitialized).toBe(true);store.subscribe(()=>console.log('updating'));awaitwaitFor(()=>result.current.isSuccess,{timeout: 5000});expect(result.current.data).toEqual(TEST_SETTINGS);});
Custom renderer
constrenderHookWithContext=(hook,{ initialState, store =configureStore({reducer: rootReducer,preloadedState: initialState})}={})=>({
store,
...renderHook(hook,{wrapper: ({ children })=><Providerstore={store}>{children}</Provider>,}),});
What you did:
I am trying to test a ReactQuery-like Hook I have for my redux store. It looks at the store's status and dispatches a fetchSettings async action if it is idle while returning isLoading. When the data is loaded and updated in the store it returns isSuccess and the data.
What happened:
When I run the test I get a pass on the initial expect for isUnitialized but the hooks return values are never updated. Despite the fact that the store subscription shows logs that the store is updated 3 times as expected.
Problem description:
It looks like useSelector is not returning new updates to the store under the test - it does seem to work in my production component.
The text was updated successfully, but these errors were encountered:
react-hooks-testing-library
version: 7.0.2react
version: 17.0.1react-dom
version (if applicable): 17.0.1react-test-renderer
version (if applicable): 17.0.1node
version: 14.17npm
(oryarn
) version: 8.4.0Relevant code or config:
Hook:
test:
Custom renderer
What you did:
I am trying to test a ReactQuery-like Hook I have for my redux store. It looks at the store's status and dispatches a
fetchSettings
async action if it isidle
while returningisLoading
. When the data is loaded and updated in the store it returnsisSuccess
and thedata
.What happened:
When I run the test I get a pass on the initial expect for
isUnitialized
but the hooks return values are never updated. Despite the fact that the store subscription shows logs that the store is updated 3 times as expected.Problem description:
It looks like useSelector is not returning new updates to the store under the test - it does seem to work in my production component.
The text was updated successfully, but these errors were encountered: