Skip to content

Commit db05d13

Browse files
author
Charley
committed
test: add await-async-events tests
1 parent 5585d68 commit db05d13

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/node-utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export function isPromisesArrayResolved(node: TSESTree.Node): boolean {
218218
* - it's returned from a function
219219
* - has `resolves` or `rejects` jest methods
220220
* - has `toResolve` or `toReject` jest-extended matchers
221+
* - has a jasmine async matcher
221222
*/
222223
export function isPromiseHandled(nodeIdentifier: TSESTree.Identifier): boolean {
223224
const closestCallExpressionNode = findClosestCallExpressionNode(
@@ -521,10 +522,13 @@ export function getAssertNodeInfo(
521522
}
522523

523524
const matcherNamesHandlePromise = [
525+
// jest matchers
524526
'resolves',
525527
'rejects',
528+
// jest-extended matchers
526529
'toResolve',
527530
'toReject',
531+
// jasmine matchers
528532
'toBeRejected',
529533
'toBeRejectedWith',
530534
'toBeRejectedWithError',

tests/lib/rules/await-async-events.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ ruleTester.run(RULE_NAME, rule, {
178178
`,
179179
options: [{ eventModule: 'fireEvent' }] as const,
180180
},
181+
182+
...FIRE_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({
183+
code: `
184+
import { fireEvent } from '${testingFramework}'
185+
test('jest async matchers are valid', async () => {
186+
expect(fireEvent.${eventMethod}(getByLabelText('username'))).rejects.toBe("foo")
187+
expect(fireEvent.${eventMethod}(getByLabelText('username'))).resolves.toBe("foo")
188+
})
189+
`,
190+
options: [{ eventModule: 'fireEvent' }] as const,
191+
})),
192+
193+
...FIRE_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({
194+
code: `
195+
import { fireEvent } from '${testingFramework}'
196+
test('jest-extended async matchers are valid', async () => {
197+
expect(fireEvent.${eventMethod}(getByLabelText('username'))).toReject()
198+
expect(fireEvent.${eventMethod}(getByLabelText('username'))).toResolve()
199+
})
200+
`,
201+
options: [{ eventModule: 'fireEvent' }] as const,
202+
})),
203+
204+
...FIRE_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({
205+
code: `
206+
import { fireEvent } from '${testingFramework}'
207+
test('jasmine async matchers are valid', async () => {
208+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBeRejected()
209+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBeRejectedWith("foo")
210+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBeRejectedWithError("foo")
211+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBePending()
212+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBeResolved()
213+
expectAsync(fireEvent.${eventMethod}(getByLabelText('username'))).toBeResolvedTo("foo")
214+
})
215+
`,
216+
options: [{ eventModule: 'fireEvent' }] as const,
217+
})),
181218
]),
182219

183220
...USER_EVENT_ASYNC_FRAMEWORKS.flatMap((testingFramework) => [

0 commit comments

Comments
 (0)