Problem Statement I’m using create react app with Jest. In my test, I simply want to render out a component that needs history passed to the state before it can load. I’ve been researching and trying to get to this to work for awhile. The source I’ve been using shows how to pass the history …
Tag: jestjs
jest is failing to find `bota` and `atob`
Creating a jest test like: fails with however, node does define btoa as of node 16, and so the following: correctly outputs YWFh. How can I configure jest to get this test to pass? Clearly something is happening in the jest test runner to not execute in the current node environment, or otherwise is stripping …
Angular v13 Jest with nx test – SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode
I tried to follow every comment with a possible solution here to the letter. I relied on an example project on github as well which works perfectly. This also started to happen to me after updating everything manually and when running the nx test command, occurrs this error. My jest.config.js inside apps/my-a…
How to test cloned HTML templates and generated by JS HTML elements with Jest?
I have the following HTML: And I have the following plain JS file script.js: Basically, once the class Manager is instantiated, it calls the init() method. This method is fetching data from an API, and once fetched, it generates HTML elements for each element of the received data.list array. When an element i…
Can I rethrow a rejected await function, and catch it immediately
I’d like to catch all my exceptions in one place, but I can’t do that currently: There is an important thing to note if you like more try/catch. The following code won’t catch the error: […] Remember: a rejected Promise will propagate up in the stack unless you catch it. To catch the e…
MUI5 not working with jest – SyntaxError: Cannot use import statement outside a module
Reproducible repo: https://github.com/hutber/cannotusestatement What is more worrying is: https://codesandbox.io/s/vigilant-bartik-bmz8x in the sandbox the tests pass. However if you checkout the above repo, which was imported into this sandbox it will not pass locally. I have no doubt that the issue is my je…
Unable to run JEST test
I’m facing an issue when I try to import something using require() function in jest test file. script2.test.js Package.json babel.config.cjs I’m getting following errors when I run the test using npm test I’m new to JEST, any help is much appreciated. My Node version is 14.17.3 Thanks you. A…
Jest coverage tools fail
During in my react-native project, during test execution, Jest shows coverage and creates coverage reports. Jest config: During testing I get errors: in files which are generated during creation of coverage folder: So, in jest documentation we see that we can specify jsdom environment in file which produces e…
Looping through an array and run a Jest test for each element does not work
I have a very large array of JSON objects. I need to run Jest tests on each individual element. I tried iterating through the array first and then write the tests in the loop as such: However with this code Jest complains that ” Your test suite must contain at least one test.” Do I have to loop ov…
Puppeteer not picking up dialog box
I’m trying to test for an alert box in Puppeteer: However, it doesn’t seem to return the message inside the alert box (even though I’ve confirmed it works doing it manually). Any ideas why page.on(‘dialog’, async dialog => { isn’t being entered? Answer I’m not sure…