Skip to content

Commit

Permalink
feat: support errors to be a message
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 6, 2024
1 parent 318c75a commit 1db89e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export function createRuleTester(options: RuleTesterOptions): RuleTesterResult {
messages.forEach(rewriteMessage)

if (_case.errors) {
if (typeof _case.errors === 'number') {
if (typeof _case.errors === 'function') {
_case.errors(messages)
}
else if (typeof _case.errors === 'number') {
expect.soft(messages.length, 'number of error messages').toBe(_case.errors)
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ValidTestCaseBase extends Linter.FlatConfig {
}

export interface InvalidTestCaseBase extends ValidTestCaseBase {
errors?: number | (string | Partial<Linter.LintMessage>)[]
errors?: number | (string | Partial<Linter.LintMessage>)[] | ((errors: Linter.LintMessage[]) => void)
output?: string | ((output: string) => void)
}

Expand Down

0 comments on commit 1db89e9

Please sign in to comment.