Open
Description
The done
callback in Jest can be used to fail tests, either by done.fail()
or passing anything into done
, like this: done('fail')
. Both of these cases are handled wrong by the rule now - always replacing done
with resolve
, which only works when it's not supposed to fail.
This will make the rule more complicated (since it has to figure out how the callback is used instead of just replacing where done
comes from). When we get to this I'd also prefer to use resolve
as the name of the argument instead of the current logic (which reuses the name given to the done
callback).
I've added 2 failing tests:
Index: src/rules/__tests__/no-done-callback.test.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/rules/__tests__/no-done-callback.test.ts b/src/rules/__tests__/no-done-callback.test.ts
--- a/src/rules/__tests__/no-done-callback.test.ts (revision 9c31a8db90310fd1f0ee70e954683d718fcfb6de)
+++ b/src/rules/__tests__/no-done-callback.test.ts (date 1618102970325)
@@ -412,5 +412,41 @@
},
],
},
+ {
+ code: 'test("something", done => {done("fail");})',
+ errors: [
+ {
+ messageId: 'noDoneCallback',
+ line: 1,
+ column: 19,
+ suggestions: [
+ {
+ messageId: 'suggestWrappingInPromise',
+ data: { callback: 'done' },
+ output:
+ 'test("something", () => {return new Promise((_, reject) => {reject("error");})})',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ code: 'test("something", done => {done.fail("fail");})',
+ errors: [
+ {
+ messageId: 'noDoneCallback',
+ line: 1,
+ column: 19,
+ suggestions: [
+ {
+ messageId: 'suggestWrappingInPromise',
+ data: { callback: 'done' },
+ output:
+ 'test("something", () => {return new Promise((_, reject) => {reject("error");})})',
+ },
+ ],
+ },
+ ],
+ },
],
});