File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
packages/node_modules/overmind-react/src Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -367,4 +367,35 @@ describe('React', () => {
367367 expect ( renderCount ) . toBe ( 1 )
368368 expect ( tree ) . toMatchSnapshot ( )
369369 } )
370+ test ( 'should throw an error without provider' , ( ) => {
371+ expect . assertions ( 1 )
372+
373+ const config = {
374+ state : {
375+ foo : 'bar' ,
376+ } ,
377+ }
378+
379+ type IConfig = {
380+ state : {
381+ foo : typeof config . state . foo
382+ }
383+ }
384+
385+ const useApp = createHook < IConfig > ( ) ;
386+
387+ const FooComponent = ( ) => {
388+ const { state } = useApp ( ) ;
389+
390+ return < h1 > { state . foo } </ h1 >
391+ }
392+
393+ expect ( ( ) => {
394+ renderer
395+ . create (
396+ < FooComponent />
397+ )
398+ . toJSON ( )
399+ } ) . toThrow ( Error )
400+ } )
370401} )
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ export const createHook = <Config extends IConfiguration>(): (() => {
9797 return ( ) => {
9898 const overmind = react . useContext ( context ) as Overmind < Config >
9999
100- if ( ! overmind ) {
100+ if ( ! ( overmind as any ) . mode ) {
101101 throwMissingContextError ( )
102102 }
103103
You can’t perform that action at this time.
0 commit comments