Skip to content

Commit

Permalink
New: Support output option for rule-tester tests of suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
wdoug committed Nov 11, 2019
1 parent 36d2b3b commit 6f904f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -612,6 +612,13 @@ class RuleTester {
assertSuggestionKeyEquals("desc");
assertSuggestionKeyEquals("messageId");
assertSuggestionKeyEquals("fix");

if (hasOwnProperty(expectedSuggestion, "output")) {
const fix = actualSuggestion.fix;
const codeWithAppliedSuggestion = item.code.slice(0, fix.range[0]) + fix.text + item.code.slice(fix.range[1]);

assert.strictEqual(codeWithAppliedSuggestion, expectedSuggestion.output, "Expected the applied suggestion fix to match the test suggestion output");
}
});
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/no-useless-escape.js
Expand Up @@ -154,10 +154,10 @@ ruleTester.run("no-useless-escape", rule, {
type: "Literal",
suggestions: [{
messageId: "removeEscape",
fix: { range: [11, 12], text: "" }
output: "var foo = /;/;"
}, {
messageId: "escapeBackslash",
fix: { range: [11, 11], text: "\\" }
output: "var foo = /\\\\;/;"
}]
}]
},
Expand All @@ -171,10 +171,10 @@ ruleTester.run("no-useless-escape", rule, {
type: "Literal",
suggestions: [{
messageId: "removeEscape",
fix: { range: [11, 12], text: "" }
output: "var foo = \"'\";"
}, {
messageId: "escapeBackslash",
fix: { range: [11, 11], text: "\\" }
output: "var foo = \"\\\\'\";"
}]
}]
},
Expand Down

0 comments on commit 6f904f0

Please sign in to comment.