Search code examples
reactjsreact-testing-libraryreact-selectcodesandboxuser-event

Error using userEvent with React Testing Library and react-select AsyncSelect (but only in CodeSandbox?)


I created this CodeSandbox so I could demonstrate a problem with related code (the onChange not firing in a test):

https://codesandbox.io/s/festive-tree-xkw8s?file=/src/App.test.js

However in CodeSandbox I can't even get that far because as soon as I call

userEvent.type(securityField, 'abc{enter}')

I get a set this error in the console:

Error: Uncaught [TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.]

and as a result the loadOptions callback of AsynSelect is never triggered (locally I'm not having any issue with that, just the onChange which isn't firing).

I have not been able to find any examples of or guidance on this error. I haven't used CodeSandbox a lot so maybe I'm missing something basic.

I am not seeing this error in my local environment but I am trying to solve it because I want to finish setting up my original problem.


Solution

  • You want to use react-select-event for interacting with your react-select in testing. This was made specifically for testing with react-testing-library.