ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
26 lines (24 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const chai_1 = require("chai");
const testHelpers_1 = require("./../testHelpers");
describe("CallExpression", () => {
describe("getReturnType", () => {
function doTest(text, expectedTypes) {
const { sourceFile } = testHelpers_1.getInfoFromText(text);
const callExpressions = sourceFile.getDescendantsOfKind(ts.SyntaxKind.CallExpression);
chai_1.expect(callExpressions.map(c => c.getReturnType().getText())).to.deep.equal(expectedTypes);
}
it("should get the call expression's return type", () => {
doTest("const func = () => ''; const myVar = func();", ["string"]);
});
it("should get the call expression's return type when void", () => {
doTest("const func = () => {}; const myVar = func();", ["void"]);
});
it("should get the call expression's return type when chained", () => {
doTest("const func = () => () => 4; const myVar = func()();", ["number", "() => number"]);
});
});
});
//# sourceMappingURL=callExpressionTests.js.map