Deven Bansod 8b57a3e3b9 Migrate a few packages' tests to use Jest Expect (see below)
* Migrate the following packages' tests:
    * babel-helper-annotate-as-pure
    * babel-helper-module-imports
    * babel-helper-transform-fixture-test-runner
    * babel-highlight
    * babel-node
    * babel-plugin-transform-modules-commonjs
    * babel-preset-env-standalone
    * babel-preset-env
    * babel-preset-es2015
    * babel-preset-react
    * babel-standalone
    * babel-template
    * babel-traverse
    * babel-types
2018-03-24 16:22:10 +05:30

78 lines
1.8 KiB
JavaScript

import traverse from "../lib";
import { parse } from "babylon";
describe("path/ancestry", function() {
describe("isAncestor", function() {
const ast = parse("var a = 1; 'a';");
it("returns true if ancestor", function() {
const paths = [];
traverse(ast, {
"Program|NumericLiteral"(path) {
paths.push(path);
},
});
const [programPath, numberPath] = paths;
expect(programPath.isAncestor(numberPath)).toBeTruthy();
});
it("returns false if not ancestor", function() {
const paths = [];
traverse(ast, {
"Program|NumericLiteral|StringLiteral"(path) {
paths.push(path);
},
});
const [, numberPath, stringPath] = paths;
expect(stringPath.isAncestor(numberPath)).toBeFalsy();
});
});
describe("isDescendant", function() {
const ast = parse("var a = 1; 'a';");
it("returns true if descendant", function() {
const paths = [];
traverse(ast, {
"Program|NumericLiteral"(path) {
paths.push(path);
},
});
const [programPath, numberPath] = paths;
expect(numberPath.isDescendant(programPath)).toBeTruthy();
});
it("returns false if not descendant", function() {
const paths = [];
traverse(ast, {
"Program|NumericLiteral|StringLiteral"(path) {
paths.push(path);
},
});
const [, numberPath, stringPath] = paths;
expect(numberPath.isDescendant(stringPath)).toBeFalsy();
});
});
describe("getStatementParent", function() {
const ast = parse("var a = 1;");
it("should throw", function() {
expect(function() {
traverse(ast, {
Program(path) {
path.getStatementParent();
},
});
}).toThrow(/File\/Program node/);
});
});
});