question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem async/await jest test

See original GitHub issue
const 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:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
ValSolcommented, Jan 9, 2018

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!

3reactions
ValSolcommented, Jan 23, 2018

Figuring out how to make the webdriver.io + mocha work with RSK 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found