ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
58 lines (56 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const chai_1 = require("chai");
const testHelpers_1 = require("./../testHelpers");
describe("Diagnostic", () => {
const { tsSimpleAst, sourceFile } = testHelpers_1.getInfoFromText("const a: string;", { disableErrorCheck: true });
tsSimpleAst.addSourceFileFromText("file.ts", "interface MyInterface { declare prop: string; }");
const diagnostics = tsSimpleAst.getDiagnostics();
const constError = diagnostics[1];
it("should have two errors overall", () => {
chai_1.expect(diagnostics.length).to.equal(2);
});
describe("getting diagnostics from a source file", () => {
const sourceFileDiagnostics = sourceFile.getDiagnostics();
it("should have the correct error in the original source file", () => {
chai_1.expect(sourceFileDiagnostics.length).to.equal(1);
});
});
describe("getMessageText", () => {
it("should get the message text", () => {
chai_1.expect(constError.getMessageText()).to.equal(`'const' declarations must be initialized.`);
});
});
describe("getCategory", () => {
it("should get the category", () => {
chai_1.expect(constError.getCategory()).to.equal(ts.DiagnosticCategory.Error);
});
});
describe("getCode", () => {
it("should get the code", () => {
chai_1.expect(constError.getCode()).to.equal(1155);
});
});
describe("getStart", () => {
it("should get the start", () => {
chai_1.expect(constError.getStart()).to.equal(6);
});
});
describe("getLength", () => {
it("should get the length", () => {
chai_1.expect(constError.getLength()).to.equal(1);
});
});
describe("getSource", () => {
it("should get the source", () => {
chai_1.expect(constError.getSource()).to.be.undefined;
});
});
describe("getSourceFile", () => {
it("should get the source file", () => {
chai_1.expect(constError.getSourceFile()).to.equal(sourceFile);
});
});
});
//# sourceMappingURL=diagnosticTests.js.map