@testing-library/react version: 10.4.4Running 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";
Hi @adamransom!
Thanks for this.
Whats the React version you're running?
I believe 16.13.1!
@adamransom I tried to reproduce this one with CRA (I upgraded to jest-environment-jsdom-sixteen), using RTL version 10.4.4 and it wasn't reproduced.
Any chance to get a reproduction of this one in codesandbox?
Interesting, thanks for trying to reproduce. I will attempt a reproduction in codesandbox, but it sounds like it may be something a bit more subtle in our config/package dependencies!
Maybe I'll be able to understand this one through the package.json if you want to attach it.
Maybe I'll be able to understand this one through the package.json if you want to attach it.
Good idea, here it is: https://pastebin.com/raw/75Tu9Jfz
Two questions:
testing-library/react is a dependency and not a devDependency?<rootDir>/node_modules/@testing-library/react and <rootDir>/node_modules/react to the transformIgnorePatterns and run the tests please?I also can't create a repro on codesandbox, so I guess it is something very fiddly with my config.
Full error, in case it is helpful:
4 TypeError: Cannot read property 'version' of undefined
5
6 1 | import React from "react";
7 2 | import "@testing-library/jest-dom/extend-expect";
8 > 3 | import { fireEvent, render } from "@testing-library/react";
9 | ^
10 4 | import userEvent from "@testing-library/user-event";
11 5 | import { Router } from "react-router-dom";
12 6 | import { createMemoryHistory } from "history";
13
14 at Object.<anonymous> (node_modules/@testing-library/react/dist/flush-microtasks.js:28:82)
15 at Object.<anonymous> (node_modules/@testing-library/react/dist/pure.js:52:47)
16 at Object.<anonymous> (node_modules/@testing-library/react/dist/index.js:7:13)
17 at Object.<anonymous> (spec/javascript/support/react-testing-library.js:3:1)
Are you mocking React somewhere? Any chance to see the jest setup file also?
Thanks!
I don't think we are mocking React (knowingly). Our setup file is just:
import "jest-prop-type-error";
import ReactModal from "react-modal";
ReactModal.setAppElement(document.body);
window.alert = () => {};
we just ran into the same issue when upgrading from 9.1.4 to 10.4.4
Could someone make a reproduction here? It's much easier to determine the problem with a minimal reproduction. https://kcd.im/rtl-help
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.
same for us, breaks after upgrading
@urlaubsbaron, @adamransom can one of you please attach your Webpack config?
Here you go: https://pastebin.com/2s7t6Kup
We use rails/webpacker so the config is auto-generated and might look a bit funky, not sure!
@MatanBobi
v10.4.4 was update to verify the React version:
@testing-library/react/dist/flush-microtasks.js
const isModernScheduleCallbackSupported = satisfies(React.version, '>16.8.6', {
includePrerelease: true,
})
transpiled code would be :
const isModernScheduleCallbackSupported = Scheduler && (0, _satisfies.default)(_react.default.version, '>16.8.6', {
includePrerelease: true
});
_react.default is undefined.
reverting to v10.4.3 worked for me.
thanks @michael5891, If you'll be able to provide a reproduction repo it would really help (https://kcd.im/rtl-help).
@adamransom - I saw that in your jest configs you have:
"moduleDirectories": [
"node_modules",
"app/javascript",
""
]
This is a long-shot but I was able to reproduce this on my local env and when I removed the empty string at the bottom this one was fixed.
I think it's a long-shot because I don't really understand why it matters, but maybe worth a try :)
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!
looks like we had a similar problem, just in our case it was "./" entry in moduleDirectories that caused this issue:
"moduleDirectories": [
"./",
"node_modules",
"bower_components"
],
changing this to "<rootDir>" as suggested above got things working again:
"moduleDirectories": [
"<rootDir>",
"node_modules",
"bower_components"
],
Thank you everyone!
@urlaubsbaron, @michael5891 can you please have a look if you have the same jest config by any chance so we'll be able to close this one?
Same applies for us:
moduleDirectories: ['node_modules', './'],
I will replace it with
moduleDirectories: ['node_modules', '<rootDir>'],
thanks for clarification
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.
Most helpful comment
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!