Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
fix(error): can handle `// => *Error
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 30, 2016
1 parent 05624b0 commit 95babac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function extractionBody(ast) {
export function wrapAssert(actualNode, expectedNode) {
assert(typeof expectedNode !== "undefined");
var type = expectedNode.type || extractionBody(expectedNode).type;
if (type === Syntax.Identifier && expectedNode.name === "Error") {
if (type === Syntax.Identifier && /^[a-zA-Z]*?Error$/.test(expectedNode.name)) {
return toAST`assert.throws(function() {
${actualNode}
}, ${expectedNode})`;
})`;
} else if (type === Syntax.Identifier && expectedNode.name === "NaN") {
return toAST`assert(isNaN(${actualNode}));`;
} else if (isConsole(actualNode)) {
Expand Down
17 changes: 16 additions & 1 deletion test/comment-to-assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ function parseToAST(code) {
}
describe("comment-to-assert", function() {
describe("#toAssertFromSource", function() {
it("test", function() {

function sum(...values) {
return values.reduce((total, value) => {
console.assert(Number.isFinite(value), `${ value }は有限数ではありません`);
return total + Number(value);
}, 0);
}

var x = 1, y, z = 10;
assert.throws(function() {
sum(x, y, z);
}, Error);

});
it("should return code", function() {
var code = "var a = 1;";
var result = toAssertFromSource(code, "file.js");
Expand Down Expand Up @@ -126,7 +141,7 @@ describe("comment-to-assert", function() {
var result = toAssertFromAST(AST);
var expected = `assert.throws(function() {
throw new Error("error");
}, Error);`;
});`;
astEqual(result, expected);
});
it("could handle NaN", function() {
Expand Down

0 comments on commit 95babac

Please sign in to comment.