diff --git a/src/rules/padding-around-expect-groups.ts b/src/rules/padding-around-expect-groups.ts index e9aa198..4190bcf 100644 --- a/src/rules/padding-around-expect-groups.ts +++ b/src/rules/padding-around-expect-groups.ts @@ -18,6 +18,21 @@ export const config: Config[] = [ prevStatementType: StatementType.ExpectToken, nextStatementType: StatementType.ExpectToken, }, + { + paddingType: PaddingType.Always, + prevStatementType: StatementType.Any, + nextStatementType: StatementType.ExpectTypeOfToken, + }, + { + paddingType: PaddingType.Always, + prevStatementType: StatementType.ExpectTypeOfToken, + nextStatementType: StatementType.Any, + }, + { + paddingType: PaddingType.Any, + prevStatementType: StatementType.ExpectTypeOfToken, + nextStatementType: StatementType.ExpectTypeOfToken, + }, ]; export default createPaddingRule( diff --git a/src/utils/padding.ts b/src/utils/padding.ts index 8a2542f..2724f23 100644 --- a/src/utils/padding.ts +++ b/src/utils/padding.ts @@ -18,6 +18,7 @@ export const enum StatementType { BeforeEachToken, DescribeToken, ExpectToken, + ExpectTypeOfToken, FdescribeToken, FitToken, ItToken, @@ -175,6 +176,7 @@ const statementTesters: { [T in StatementType]: StatementTester } = { [StatementType.BeforeEachToken]: createTokenTester('beforeEach'), [StatementType.DescribeToken]: createTokenTester('describe'), [StatementType.ExpectToken]: createTokenTester('expect'), + [StatementType.ExpectTypeOfToken]: createTokenTester('expectTypeOf'), [StatementType.FdescribeToken]: createTokenTester('fdescribe'), [StatementType.FitToken]: createTokenTester('fit'), [StatementType.ItToken]: createTokenTester('it'), diff --git a/tests/padding-around-expect-groups.test.ts b/tests/padding-around-expect-groups.test.ts index fbe66a7..f775379 100644 --- a/tests/padding-around-expect-groups.test.ts +++ b/tests/padding-around-expect-groups.test.ts @@ -1,7 +1,7 @@ -import type { TSESLint } from '@typescript-eslint/utils'; import rule, { RULE_NAME } from '../src/rules/padding-around-expect-groups'; import { ruleTester } from './ruleTester'; +import { InvalidTestCase } from "@typescript-eslint/rule-tester" const testCase = { code: ` @@ -61,6 +61,16 @@ test('awaited expect', async () => { await somethingElseAsync(); await expect(hasAPromise()).resolves.toEqual('foo'); }); + +test('expectTypeOf test', () => { + const hoge = 123; + expectTypeOf(hoge).toBeNumber(); + expectTypeOf(hoge).toBeNumber(); + const foo = "abc"; + // Comment + expectTypeOf(foo).toBeString(); + expectTypeOf(foo).toBeString(); +}); `, output: ` foo(); @@ -129,6 +139,19 @@ test('awaited expect', async () => { await expect(hasAPromise()).resolves.toEqual('foo'); }); + +test('expectTypeOf test', () => { + const hoge = 123; + + expectTypeOf(hoge).toBeNumber(); + expectTypeOf(hoge).toBeNumber(); + + const foo = "abc"; + + // Comment + expectTypeOf(foo).toBeString(); + expectTypeOf(foo).toBeString(); +}); `, errors: [ { @@ -181,8 +204,23 @@ test('awaited expect', async () => { line: 56, column: 3, }, + { + messageId: 'missingPadding', + line: 61, + column: 3, + }, + { + messageId: 'missingPadding', + line: 63, + column: 3, + }, + { + messageId: 'missingPadding', + line: 65, + column: 3, + }, ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; +} satisfies InvalidTestCase<'missingPadding', never>; ruleTester.run(RULE_NAME, rule, { valid: [testCase.output],