// useInput.test.jsimport{renderHook,act}from'@testing-library/react-hooks';import{Provider}from'react-redux';import{createStore}from'redux';importinputReducerfrom'./store';// Assume this exports the reducerimportuseInputfrom'./useInput';// Helper function to render hook with ReduxconstrenderHookWithRedux=(hook,{initialState,store=createStore(inputReducer,initialState)}={})=>{constwrapper=({children})=><Providerstore={store}>{children}</Provider>;
returnrenderHook(hook,{wrapper});};test('should update value after rerender with new initial state',()=>{const{result,rerender}=renderHookWithRedux(({initialValue})=>useInput(initialValue),{initialState:{value:'initial'}});expect(result.current.value).toBe('initial');// Create a new store with a different initial stateconstnewStore=createStore(inputReducer,{value:'updated'});// Rerender with the new storererender({initialState:{value:'updated'},store:newStore});expect(result.current.value).toBe('updated');});
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)