Problem async/await jest test
See original GitHub issueconst testAsync = () => Promise.resolve('hello world');
describe('async await test', () => {
test('try 1', async () => {
const result = await testAsync();
expect(result).toBe('hello world');
});
});
async await test
encountered a declaration exception (5ms)
async await test › encountered a declaration exception
ReferenceError: regeneratorRuntime is not defined
4 |
5 | describe('async await test', () => {
> 6 | test('try 1', async () => {
7 | const result = await testAsync();
8 | expect(result).toBe('hello world');
9 | });
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Testing Asynchronous Code - Jest
Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will...
Read more >Testing with Jest & async/await - DEV Community
Testing async functions. Seed some data to test; await first and expect later; Use resolves to await the result. Test error handling.
Read more >Async/Await test with Jest not working in Node js
I'm trying to test an async call with Jest in Node like this: it('testing to sign up feature', async (done) => { await...
Read more >Use async-await with done does not work since v27. #11404
The advantage of async-await and e.g. setTimeout. But since async transforms the return type from void to Promise<void> Jest 27 detects it as...
Read more >An Async Example · Jest
Error handling # ... Errors can be handled in the standard JavaScript way: Either using .catch() directly on a Promise or through try-catch...
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 FreeTop 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
Top GitHub Comments
Found a way:
In the file jest.config.js set:
setupFiles: ["<rootDir>/jest.setup.js"],
create new file jest.setup.js with this content:
import '@babel/polyfill';
Working!
Figuring out how to make the
webdriver.io + mocha
work withRSK
found another way for solution the issue. Instead of changing jest.config.js and adding jest.setup.js file we:yarn add --dev @babel/runtime@7.0.0-beta.36 @babel/plugin-transform-runtime@7.0.0-beta.36
and insert this row:
plugins: [['@babel/plugin-transform-runtime', { polyfill: false }]],
in the .babelrc.js file