Getting "dispatcher.useContext is not a function" when testing in Jest with hooks
See original GitHub issueDo you want to request a feature or report a bug?
Bug?
What is the current behavior?
I know it is still in alpha, so sorry for early posting. When testing components in Jest using react-test-renderer, I am getting dispatcher.useContext is not a function
whenever I am trying to use useContext
hook.
What is the expected behavior?
Test should pass with no issues.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.7-alpha.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Dispatch is not a function useContext/useReducer React hooks
I'm kinda new to redux style state management stuff in redux. I keep getting the error "TypeError: dispatch is not a function". App.js...
Read more >React Hooks jest testing - method is not a function-Reactjs
Coding example for the question React Hooks jest testing - method is not a function-Reactjs.
Read more >Uncaught TypeError: dispatch is not a function : r/reactjs - Reddit
I am trying to use the dispatch function to enact a state change and reload a component once a user clicks a button....
Read more >Advanced React - useContext and useReducer hooks
Vocab · context - an API given to us by React, allowing for the passing of information to child components without the use...
Read more >Comprehensible Guide to testing with Jest and Enzyme | react ...
Simulate button click; Check to see if a particular function was called. Why is implementation brittle? Testing implementation (function name); Not behavior ( ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK, I figured it out … I was using react-test-renderer from 16.6.
And here is a repro on CodeSandbox
https://codesandbox.io/s/pm44n0lyxm
Just view tests to get the same error as I do.