You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an app created with create-react-app, and wanted to add some tests. One component I am trying to test requires that I import 'webrtc-adapter';. When I run npm test jest complains that Jest encountered an unexpected token with the details in the code block below. From jestjs/jest#2081, I believe this is because jest isn't transforming the es6 import within the webrtc-adapter module into something it understands. The recommended solution in the other issue, as well as the one in the output from jest require modifying the jest config or the babel config which in turn requires ejecting the app so far as I can tell, however I'd like to avoid that if possible. So I'm asking if there is a way to get jest to work, without ejecting the app.
Hi @cam-narzt, that's correct. Basically, the author of that package needs to ship it as a CommonJS/UMD bundle, have export listed in package.json under main, and then include the ES module in the module field.
That way you get the best of both worlds, as Node/Jest will pick up the CJS module, and Webpack and other modern build tools can use the ES module.
If you don't need this as a part of your tests, you can mock it too. Simple create an __mocks__ directory in root, and create a file called webrtc-adapter that mocks anything that gets called during testing.
I have an app created with
create-react-app
, and wanted to add some tests. One component I am trying to test requires that Iimport 'webrtc-adapter';
. When I runnpm test
jest complains thatJest encountered an unexpected token
with the details in the code block below. From jestjs/jest#2081, I believe this is because jest isn't transforming the es6 import within the webrtc-adapter module into something it understands. The recommended solution in the other issue, as well as the one in the output from jest require modifying the jest config or the babel config which in turn requires ejecting the app so far as I can tell, however I'd like to avoid that if possible. So I'm asking if there is a way to get jest to work, without ejecting the app.The text was updated successfully, but these errors were encountered: