Issues using React components in test environment
See original GitHub issueWe’ve recently replaced our hand-rolled components with the ones provided by our toolkit. All works well when running the extension normally, but we get the following exception when running our tests:
/Users/dee/Programming/work/nordic/vscode-nrf-connect/node_modules/@vscode/webview-ui-toolkit/react/index.js:3
import { provideReactWrapper } from '@microsoft/fast-react-wrapper';
^^^^^^
SyntaxError: Cannot use import statement outside a module
This is being hit when our test imports the React component that makes use of the toolkit components. For context, our source code and tests are compiled using tsc -p .
, and are run through the runTests
utility provided by @vscode/test-electron
. This means there’s no bundling stage involved, which I guess is why we’re not seeing this when the extension is running normally.
Is it possible that there’s something misconfigured in the library, i.e. a missing "type": "module"
in the package.json
file?
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Testing Environments - React
In an environment where you can't simulate a DOM (e.g. testing React Native components on Node.js), you could use event simulation helpers to...
Read more >Unit Testing Behavior of React Components with Test-Driven ...
The internet is full of excellent examples of how to unit test React components that have purely presentational concerns. This is fairly easy...
Read more >The current testing environment is not configured to support ...
I noticed this after switching from jest to vitest, and not changing anything else.
Read more >A Practical Guide to Testing React Applications ... - LambdaTest
This article on React Testing explores different methods of testing React components and also dive into some advanced testing principles and ...
Read more >How to Test React Components: the Complete Guide
I will first show you the React component and then the tests for it, with detailed explanations of each. You can also follow...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey, thanks for looking into this!
Our extension isn’t open source unfortunately, but I created a minimal example that reproduces the issue. It implements a simple counter webview that uses the
VSCodeButton
component, as well as a couple of tests, and includes a rough approximation of our test environment. I hope it’s useful!Thanks for the bug report @deerob4!
Been a bit busy with other pressing work lately but will put it on the top of my todo list once I have some free cycles
Also thank you so much for the call out of a missing
"type": "module"
! I thought that was something I included long ago, but adding it might be a solution to some other problems I’ve been tackling with the toolkit