diff --git a/src/rules/__tests__/no-restricted-matchers.test.ts b/src/rules/__tests__/no-restricted-matchers.test.ts index f08383102..cfd6bb22f 100644 --- a/src/rules/__tests__/no-restricted-matchers.test.ts +++ b/src/rules/__tests__/no-restricted-matchers.test.ts @@ -99,6 +99,36 @@ ruleTester.run('no-restricted-matchers', rule, { }, ], }, + { + code: 'expect(a).resolves.toBe(b)', + options: [{ resolves: null }], + errors: [ + { + messageId: 'restrictedChain', + data: { + message: null, + chain: 'resolves', + }, + column: 11, + line: 1, + }, + ], + }, + { + code: 'expect(a).resolves.not.toBe(b)', + options: [{ 'resolves.not': null }], + errors: [ + { + messageId: 'restrictedChain', + data: { + message: null, + chain: 'resolves.not', + }, + column: 11, + line: 1, + }, + ], + }, { code: 'expect(a).not.toBe(b)', options: [{ 'not.toBe': null }], @@ -115,6 +145,22 @@ ruleTester.run('no-restricted-matchers', rule, { }, ], }, + { + code: 'expect(a).resolves.not.toBe(b)', + options: [{ 'resolves.not.toBe': null }], + errors: [ + { + messageId: 'restrictedChain', + data: { + message: null, + chain: 'resolves.not.toBe', + }, + endColumn: 28, + column: 11, + line: 1, + }, + ], + }, { code: 'expect(a).toBe(b)', options: [{ toBe: 'Prefer `toStrictEqual` instead' }], diff --git a/src/rules/no-restricted-matchers.ts b/src/rules/no-restricted-matchers.ts index d439ecd5b..c15da33d7 100644 --- a/src/rules/no-restricted-matchers.ts +++ b/src/rules/no-restricted-matchers.ts @@ -54,7 +54,11 @@ export default createRule< } if (modifier) { - const chain = modifier.name; + let chain: string = modifier.name; + + if (modifier.negation) { + chain += '.not'; + } if (chain in restrictedChains) { const message = restrictedChains[chain]; @@ -72,7 +76,13 @@ export default createRule< } if (matcher && modifier) { - const chain = `${modifier.name}.${matcher.name}`; + let chain: string = modifier.name; + + if (modifier.negation) { + chain += '.not'; + } + + chain += `.${matcher.name}`; if (chain in restrictedChains) { const message = restrictedChains[chain];