react-testing-library: TypeError: Cannot read property 'version' of undefined
@testing-library/reactversion: 10.4.4- Testing Framework and version: Jest v24
 - DOM Environment: jsdom-sixteen
 - React version: 16.13.1
 
What you did:
Running any test that uses @testing-library/react fails with TypeError: Cannot read property 'version' of undefined that previously used to run fine on 10.4.3.
I imagine it’s due to the version check in the latest version, but I can’t figure out if it is something that I need to change about my config to get it working again? I have a very standard setup I believe and use the library as such:
// spec/support/react-testing-library.js
import React from "react";
import "@testing-library/jest-dom/extend-expect";
export * from "@testing-library/react";
About this issue
- Original URL
 - State: closed
 - Created 4 years ago
 - Comments: 24 (10 by maintainers)
 
Same applies for us:
moduleDirectories: ['node_modules', './'],I will replace it with
moduleDirectories: ['node_modules', '<rootDir>'],thanks for clarification
looks like we had a similar problem, just in our case it was
"./"entry inmoduleDirectoriesthat caused this issue:changing this to
"<rootDir>"as suggested above got things working again:Thank you everyone!
This should be resolved with #744 which was published a few hours ago. If it’s not fixed in the next version, please comment here.
It does indeed fix it! For some reason, we used
""instead of"<rootDir>", which achieves exactly what we want. Who knows if this is a bug in Jest, RTL or even if an empty string there should be supported!Anyways, problem resolved for us, so thank you for helping!
Yeah, I did try to make a minimal reproduction quickly but couldn’t unfortunately 😞 I imagine it will involve taking my current config and rebuilding it piece by piece until the error occurs. I’ll try to do this when I have the time, but since we are using this in production we are content with simply holding off bumping the version for now.
Thanks for all the time you’ve put in so far @MatanBobi! I’ll comment again when I’ve got a reproduction.
I don’t think we are mocking React (knowingly). Our setup file is just: