2

I have trying to test the basic example provided in react-testing-library documentation. I exactly copied and pasted this code here

It's failing no matter what.

Here the failing test result:

shows the children when the checkbox is checked

    TypeError: Cannot read property 'current' of undefined

      34 | test('shows the children when the checkbox is checked', () => {
      35 |   const testMessage = 'Test Message'
    > 36 |   const {queryByText, getByLabelText, getByText} = render(
         |                                                    ^
      37 |     <HiddenMessage>{testMessage}</HiddenMessage>,
      38 |   )
      39 | 

      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:983:55)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1418:12)
      at render (node_modules/@testing-library/react/dist/pure.js:82:26)
      at Object.<anonymous> (src/components/Authentication/SignUp/index.test.js:36:52)

  ● shows the children when the checkbox is checked

    TypeError: Cannot read property 'current' of undefined

      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:983:55)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1418:12)
      at node_modules/@testing-library/react/dist/act-compat.js:57:20
      at asyncAct (node_modules/@testing-library/react/dist/act-compat.js:38:14)
      at Object.<anonymous> (node_modules/@testing-library/react/dist/index.js:28:35)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.318s, estimated 3s
Ran all test suites related to changed files.

Any ideas?

4
  • Show the code for HiddenMessage component. Commented Aug 17, 2019 at 10:48
  • I've added the link above. The code is exactly the same as the one used in the react-testing-library example. Just in case, here the link again: github.com/testing-library/react-testing-library#basic-example Commented Aug 17, 2019 at 11:05
  • 5
    Works for me. Make sure you have the latest versions of React, React DOM and testing library installed. Commented Aug 17, 2019 at 11:25
  • 2
    Yep, you were right Clarity. I've updated the version of react to the latest 16.9 and everything works fine. Commented Aug 17, 2019 at 13:46

2 Answers 2

4

I ran into this as well from my research it looks like the undefined which current is being called on is IsSomeRendererActing inside of https://github.com/facebook/react/blob/master/packages/react-dom/src/test-utils/ReactTestUtilsAct.js#L79

It looks like a global var shared between react packages. The best advise I can give is to check that react dom react and react test utils and any other react packages all are at the same version

Sign up to request clarification or add additional context in comments.

Comments

-1

This error is probably coming from inside the HiddenMessage component, rather than anything wrong in your test code. It looks like you’re trying to access current On something that doesn’t exist (maybe a ref?)

The test code looks right, you should track down where you’re trying to access current in HiddenMessage.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.