Skip to content

Commit

Permalink
Update: throw error for errors: 0 in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Apr 22, 2020
1 parent 08370d0 commit a3360c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -655,6 +655,11 @@ class RuleTester {
const messages = result.messages;

if (typeof item.errors === "number") {

if (item.errors === 0) {
assert.fail("errors of type `number` should not have value `0`");
}

assert.strictEqual(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
item.errors, item.errors === 1 ? "" : "s", messages.length, util.inspect(messages)));
} else {
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -475,6 +475,25 @@ describe("RuleTester", () => {
}, /errors array should have at least one element otherwise its a valid case/u);
});

it("should throw error for errors : 0", () => {
assert.throws(() => {
ruleTester.run(
"suggestions-messageIds",
require("../../fixtures/testers/rule-tester/suggestions")
.withMessageIds,
{
valid: [],
invalid: [
{
code: "var foo;",
errors: 0
}
]
}
);
}, /errors of type `number` should not have value `0`/u);
});

it("should not skip column assertion if column is a falsy value", () => {
assert.throws(() => {
ruleTester.run("no-eval", require("../../fixtures/testers/rule-tester/no-eval"), {
Expand Down

0 comments on commit a3360c6

Please sign in to comment.