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.

no-test-callback autofix can produce invalid code

See original GitHub issue

Hello team,

With the release of v23 our team had issues with the new recommended rules, and in particular no-test-callback.

test('my test', async (done) => {
  await myAsyncTask();
  expect(true).toBe(false);
  done();
});

This code is marked as Illegal usage of test callback which is a fair warning; I would say the done usage is more useless than illegal (but just a matter of wording here).

This code will be transformed to:

test('my test', async () => {await new Promise(done => {
  await myAsyncTask();
  expect(true).toBe(false);
  done();
})});

Which is:

  • not very pretty
  • invalid
    • as await now lives in non async method
    • if you put the async keyword you can encounter an other linter error no-async-promise-executor

This is not a bug nor an urgent matter, but I would be in favor of letting the user change his/her code instead of modifying the behaviour of the test without the user paying attention.

Have a great day,

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Nov 26, 2019
1reaction
SimenBcommented, Nov 4, 2019

FWIW we should yell at this in Jest itself at runtime - you should either use the callback or return a promise, never both

EDIT: Opened up https://github.com/facebook/jest/pull/9129 for it

Read more comments on GitHub >

github_iconTop Results From Across the Web

reported autofix bounding box is incorrect compared ... - GitHub
I confirm that I have encountered this problem which is a serious one. In my case, it appears for few records. It has...
Read more >
Auto-fix patch is wrong when multiple issue affect the same line
we introduce a separate beautifier phase (I think this is touched on in T5064) which is similar to the planned "generate code" phase...
Read more >
Can't get correct autoformat on save in Visual Studio Code ...
in Visual Studio Code with ESLint and Prettier when working on .vue files, it seems I can't get vue/max-attributes-per-line to auto-fix ...
Read more >
Writing your own ESLint Plugin: Autofix code | Frontend Mayhem
Tutorial on how to add autofix logic to your custom ESLint plugin.
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