fix traverse test to reflect the new api
This commit is contained in:
parent
71c4a29a78
commit
ac8fc24fdb
@ -65,24 +65,30 @@ suite("traverse", function () {
|
|||||||
|
|
||||||
var actual = [];
|
var actual = [];
|
||||||
|
|
||||||
traverse(ast, function (node) {
|
traverse(ast, {
|
||||||
actual.push(node);
|
enter: function (node) {
|
||||||
|
actual.push(node);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(actual, expect);
|
assert.deepEqual(actual, expect);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("traverse falsy parent", function () {
|
test("traverse falsy parent", function () {
|
||||||
traverse(null, function () {
|
traverse(null, {
|
||||||
throw new Error("should not be ran");
|
enter: function () {
|
||||||
|
throw new Error("should not be ran");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("traverse unknown type", function () {
|
test("traverse unknown type", function () {
|
||||||
traverse({
|
traverse({
|
||||||
type: "FooBar"
|
type: "FooBar"
|
||||||
}, function () {
|
}, {
|
||||||
throw new Error("should not be ran");
|
enter: function () {
|
||||||
|
throw new Error("should not be ran");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,8 +100,10 @@ suite("traverse", function () {
|
|||||||
|
|
||||||
var actual = [];
|
var actual = [];
|
||||||
|
|
||||||
traverse(ast, function (node) {
|
traverse(ast, {
|
||||||
actual.push(node);
|
enter: function (node) {
|
||||||
|
actual.push(node);
|
||||||
|
}
|
||||||
}, ["MemberExpression"]);
|
}, ["MemberExpression"]);
|
||||||
|
|
||||||
assert.deepEqual(actual, expect);
|
assert.deepEqual(actual, expect);
|
||||||
@ -108,8 +116,10 @@ suite("traverse", function () {
|
|||||||
};
|
};
|
||||||
var ast2 = _.cloneDeep(ast);
|
var ast2 = _.cloneDeep(ast);
|
||||||
|
|
||||||
traverse(ast2, function (node) {
|
traverse(ast2, {
|
||||||
if (node.type === "ThisExpression") return replacement;
|
enter: function (node) {
|
||||||
|
if (node.type === "ThisExpression") return replacement;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(ast2.body[1].expression.left.object, replacement);
|
assert.equal(ast2.body[1].expression.left.object, replacement);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user