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
exportconstuseStore=()=>{constcontext=useContext(StoreContext);if(context===undefined){thrownewError('useStore must be used within a StoreProvider');}returncontext;};
I want to test that the error is thrown when context is undefined, so I've written the following test using render and Try:
importReact,{ReactElement}from'react';import{describe,Try}from'riteway';importrenderfrom'riteway/render-component';import{useStore}from'./Store.provider';constContextlessComponent=(): ReactElement=>{const{ state }=useStore();return<>{state.toString()}</>;};describe('Store/Store.provider/useStore()',async(assert)=>{assert({given: 'useStore() is called without a StoreProvider',should: 'throw an error',actual: Try(render,<ContextlessComponent/>).message,expected: 'useStore must be used within a StoreProvider',});});
The test passes, but no further tests get run after this one.
The text was updated successfully, but these errors were encountered:
I have created a
useStore
consumer hook to access context in my TypeScript React app following the pattern recommended by Kent C. Dodds:I want to test that the error is thrown when
context
isundefined
, so I've written the following test usingrender
andTry
:The test passes, but no further tests get run after this one.
The text was updated successfully, but these errors were encountered: