UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

49 lines (47 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const compiler_1 = require("./../../../../compiler"); const testHelpers_1 = require("./../../testHelpers"); describe("NamedNode", () => { describe("rename", () => { function throwTest(text) { const { firstChild } = testHelpers_1.getInfoFromText("enum MyEnum {}"); chai_1.expect(() => firstChild.rename(text)).to.throw(); } it("should set the name and rename any referenced nodes", () => { const { firstChild, sourceFile } = testHelpers_1.getInfoFromText("enum MyEnum {}\nlet myEnum: MyEnum;"); firstChild.rename("MyNewEnum"); chai_1.expect(sourceFile.getFullText()).to.equal("enum MyNewEnum {}\nlet myEnum: MyNewEnum;"); }); it("should throw if null", () => { throwTest(null); }); it("should throw if empty string", () => { throwTest(""); }); it("should throw if whitespace", () => { throwTest(" "); }); it("should throw if a number", () => { throwTest(4); }); }); describe("getName", () => { const { firstChild } = testHelpers_1.getInfoFromText("enum MyEnum {}"); it("should get the name", () => { chai_1.expect(firstChild.getName()).to.equal("MyEnum"); }); }); describe("getNameIdentifier", () => { const { firstChild } = testHelpers_1.getInfoFromText("enum MyEnum {}"); const nameNode = firstChild.getNameIdentifier(); it("should have correct text", () => { chai_1.expect(nameNode.getText()).to.equal("MyEnum"); }); it("should be of correct instance", () => { chai_1.expect(nameNode).to.be.instanceOf(compiler_1.Identifier); }); }); }); //# sourceMappingURL=namedNodeTests.js.map