8000 fix: add `before` and `after` to test case types (#20049) · eslint/eslint@dfd11de · GitHub
[go: up one dir, main page]

Skip to content

Commit dfd11de

Browse files
authored
fix: add before and after to test case types (#20049)
1 parent 6ad8973 commit dfd11de

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,8 @@ export namespace RuleTester {
22592259
only?: boolean;
22602260
languageOptions?: Linter.LanguageOptions | undefined;
22612261
settings?: { [name: string]: any } | undefined;
2262+
before?: () => void;
2263+
after?: () => void;
22622264
}
22632265

22642266
interface SuggestionOutput {

tests/lib/types/types.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,15 @@ ruleTester.run("my-rule", rule, {
19241924
{ code: "foo", filename: "test.js" },
19251925
{ code: "foo", languageOptions: { globals: { foo: true } } },
19261926
{ code: "foo", settings: { foo: true } },
1927+
{
1928+
code: "foo",
1929+
before() {
1930+
/* do something */
1931+
},
1932+
after() {
1933+
/* undo something */
1934+
},
1935+
},
19271936
RuleTester.only("foo"),
19281937
],
19291938

@@ -1954,6 +1963,12 @@ ruleTester.run("my-rule", rule, {
19541963
],
19551964
},
19561965
{ code: "foo", errors: 1, only: true },
1966+
{
1967+
code: "foo",
1968+
errors: [{ messageId: "bar" }],
1969+
before: () => {},
1970+
after: () => {},
1971+
},
19571972
// @ts-expect-error // `message` cannot be `undefined`
19581973
{ code: "foo", errors: [{ message: undefined }], only: true },
19591974
// @ts-expect-error // `messageId` cannot be `undefined`
@@ -1972,6 +1987,10 @@ ruleTester.run("my-rule", rule, {
19721987
},
19731988
],
19741989
},
1990+
// @ts-expect-error // `before` should be a function
1991+
{ code: "foo", errors: [{ messageId: "bar" }], before: {} },
1992+
// @ts-expect-error // `after` should be a function
1993+
{ code: "foo", errors: [{ messageId: "bar" }], after: void 0 },
19751994
],
19761995
});
19771996

0 commit comments

Comments
 (0)
0