UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

45 lines (43 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const testHelpers_1 = require("./../testHelpers"); describe("PropertySignature", () => { function getFirstPropertyWithInfo(code) { const opts = testHelpers_1.getInfoFromText(code); return Object.assign({}, opts, { firstProperty: opts.firstChild.getProperties()[0] }); } describe("fill", () => { function doTest(code, structure, expectedCode) { const { firstProperty, sourceFile } = getFirstPropertyWithInfo(code); firstProperty.fill(structure); chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode); } it("should not change when nothing is set", () => { doTest("interface Identifier { prop: string; }", {}, "interface Identifier { prop: string; }"); }); it("should change when setting", () => { doTest("interface Identifier { prop: string; }", { type: "number" }, "interface Identifier { prop: number; }"); }); }); describe("remove", () => { function doTest(code, nameToRemove, expectedCode) { const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(code); firstChild.getProperty(nameToRemove).remove(); chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode); } it("should remove when it's the only member", () => { doTest("interface Identifier {\n member: string;\n}", "member", "interface Identifier {\n}"); }); it("should remove when it's the first member", () => { doTest("interface Identifier {\n member: string;\n method(): string;\n member2: string;\n}", "member", "interface Identifier {\n method(): string;\n member2: string;\n}"); }); it("should remove when it's the middle member", () => { doTest("interface Identifier {\n member: string;\n member2: string;\n member3: string;\n}", "member2", "interface Identifier {\n member: string;\n member3: string;\n}"); }); it("should remove when it's the last member", () => { doTest("interface Identifier {\n member: string;\n member2: string;\n}", "member2", "interface Identifier {\n member: string;\n}"); }); }); }); //# sourceMappingURL=propertySignatureDeclarationTests.js.map