question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "dispatcher.useContext is not a function" when testing in Jest with hooks

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tomitrescakcommented, Nov 1, 2018

OK, I figured it out … I was using react-test-renderer from 16.6.

0reactions
tomitrescakcommented, Nov 1, 2018

And here is a repro on CodeSandbox

https://codesandbox.io/s/pm44n0lyxm

Just view tests to get the same error as I do.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found