UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

48 lines (46 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const testHelpers_1 = require("./../testHelpers"); describe("ConstructSignatureDeclaration", () => { function getFirstConstructSignatureWithInfo(code) { const opts = testHelpers_1.getInfoFromText(code); return Object.assign({}, opts, { firstConstructSignature: opts.firstChild.getConstructSignatures()[0] }); } describe("fill", () => { function doTest(code, structure, expectedCode) { const { firstConstructSignature, sourceFile } = getFirstConstructSignatureWithInfo(code); firstConstructSignature.fill(structure); chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode); } it("should not change when nothing is set", () => { doTest("interface Identifier { new(): any; }", {}, "interface Identifier { new(): any; }"); }); it("should change when setting", () => { doTest("interface Identifier { new(): any; }", { returnType: "string" }, "interface Identifier { new(): string; }"); }); }); describe("remove", () => { function doTest(code, indexToRemove, expectedCode) { const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(code); firstChild.getConstructSignatures()[indexToRemove].remove(); chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode); } it("should remove when it's the only member", () => { doTest("interface Identifier {\n new(): string;\n}", 0, "interface Identifier {\n}"); }); it("should remove when it's the first member", () => { doTest("interface Identifier {\n new(): string;\n prop: string;\n new(): string;\n}", 0, "interface Identifier {\n prop: string;\n new(): string;\n}"); }); it("should remove when it's the middle member", () => { doTest("interface Identifier {\n new(): string;\n new(): number;\n new(): Date;\n}", 1, "interface Identifier {\n new(): string;\n new(): Date;\n}"); }); it("should remove when it's the last member", () => { doTest("interface Identifier {\n new(): string;\n new(): number;\n}", 1, "interface Identifier {\n new(): string;\n}"); }); it("should only remove the new signature specified", () => { doTest("interface Identifier {\n new(): string;\n new(param: number): string;\n new(t: string): string;\n}", 1, "interface Identifier {\n new(): string;\n new(t: string): string;\n}"); }); }); }); //# sourceMappingURL=constructSignatureDeclarationTests.js.map