user-event: _userEvent.default.setup is not a function
@testing-library/user-eventversion: ^14.0.0-beta- DOM Environment: 8.11.1
- Node version: 14.17.4
Relevant code or config
const user = userEvent.setup()
What you did: Tests worked perfectly before updating, I just wanted the latest version for the pointer method.
Followed the latest documentation and tried multiple versions 14 and above.
Imported like so:
import userEvent from '@testing-library/user-event';
and initialised like so:
const user = userEvent.setup()
What happened:
Tests failed and receive following error:
TypeError: _userEvent.default.setup is not a function
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 39
- Comments: 38 (11 by maintainers)
Commits related to this issue
- [ui] CodeBlock: add disabled test for copy to clipboard The test currently fails due to a bug in react testing libarary (https://github.com/testing-library/user-event/issues/839). Once this is resolv... — committed to sapcc/juno by franzheidl 2 years ago
- [ui] Codeblock tabs (#185) * [ui] CodeBlock: add tabbed codeblocks * [ui] CodeBlock: add tests for tabbed codeblock * [ui] Codeblock: remove obsolete, adjust styles * [ui] CodeBlock: add dis... — committed to sapcc/juno by franzheidl 2 years ago
I just had to update to the latest version:
npm install @testing-library/user-event@latest@bijay-ps
userEvent.setup()was introduced inv14.import userEvent from '@testing-library/user-event';imports the default export of user-event asuserEvent. However, that package has no default export. Only named exports. What you probably want is@ramonaspence Thanks for the feedback. I just tagged the people who upvoted the issue or commented that they are affected. I’m happy if someone else is following this conversation and adds a reaction. 😉
It seems that the current export - although it shouldn’t - does still cause problems in some environments.
Would you please check out this alternative build of
v14.2.3and report per reaction (🎉 = works, 😕 = does not work) on this comment if it works in your environment?@Tommoore96 @laurmurclar @cwgw @creimers @wencel @k-sav @bijay-ps @JohnKearney2020 @FiveTies @jahumes @cblaine @headquarters @Joroze @AdamMescher @dimadk24 @litzebauer @Joblyn @suellenx @baNROne @MFukazawa @cedricmatalog @marcusvalverde @kokiy @johnshift @sbland @miphe @mattxyzeth @capndave @sherodtaylor @strmer15 @JimLin94 @DominicTylor @indgomez @alessandrocapra
I came across the same issue too. The temporary solution for me is I added the support type
cjsto the transform configs of Jest in the package.jsonAny update on this?
I am encountering the same exact issue on 14.4.3.
I am trying to install user-event using the install instructions available here and then call
userEvent.setup()per the instructions here.To Reproduce Steps to reproduce the behavior:
npx create-react-app .npm install --save-dev @testing-library/react @testing-library/dom @testing-library/user-eventimport {userEvent} from '@testing-library/user-event';Expected behavior
I expect, on installing
@testing-library/user-eventto be able to import userEvent and have it be defined. It is not.Screenshots If applicable, add screenshots to help explain your problem. My full test file:
Default
App.js:Desktop (please complete the following information):
Additional context I’m following the same pattern I used to install all my other npm modules, and have only been using this library for the last 2 days. The fact that I can’t even import a module out of the box that’s referred to in the docs seems weird. If I’m importing it from the wrong location it’s because the examples in the docs do not have an explicit “import” statement to access the userEvent object.
The same thing happened to me. I’m using typescript with jest Node 16 lts.
error:
TypeError: userEvent.setup is not a functionIf I run
console.log(userEvent)I get{ PointerEventsCheckLevel: [Getter], default: [Getter] }I can access the methods if I access them through
defaultbut typescript thinksuserEventis already the default. Very weird.I was having the same issue on 14.4.3 but importing it as follows works:
This solved it for me, thank you!
Also experiencing the same issue (just tried to update to latest), reverting to v13 for the moment until it’s solved.
Slightly more edge case example. Using the UserEvent library in a
bit.devcomponent had the same issue. I followed the steps above but what actually worked was moving theindex.cjsfile out of thedistto the same level as thepackage.jsonfile and renaming it toindex.js.This is the ESM export by esbuild: https://unpkg.com/browse/@testing-library/user-event@14.0.0-beta.13/dist/index.mjs
🎉 This issue has been resolved in version 14.4.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
I got same problem, here is my situation:
typeof userEvent=string;userEvent=index.cjs;jest.config.transformI got"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"It’s clearly
.cjs/.mjsfile was trasformed to it’s filename, so I fix this by adding mjs and cjs into"^(?!.*\\.(mjs|cjs|js|jsx|css|json)$)".Maybe most problems which package is
index.jswere caused byjest.config.transform.For me works after add: