no-test-callback autofix can produce invalid code
See original GitHub issueHello 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 errorno-async-promise-executor
- as await now lives in non
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:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top 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 >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
@G-Rath support released, if you wanna play with it: https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.9.0
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