UNPKG

angular-docgen

Version:

A toolkit to extract information from Angular components for documentation generation.

93 lines 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var parser_1 = require("./parser"); var fs_1 = require("fs"); var path_1 = require("path"); var component_1 = fs_1.readFileSync(path_1.resolve(__dirname, "./fixtures/component_1.txt"), "utf8").toString(); var component_2 = fs_1.readFileSync(path_1.resolve(__dirname, "./fixtures/component_2.txt"), "utf8").toString(); describe("Parser Component 1", function () { it("should parse a component decorator", function () { expect(parser_1.default(component_1).component).toMatchObject({ name: "SampleComponent", description: "Sample Component", templateUrl: "template.html", selector: "my-button", styleUrls: ["styles1.css", "styles2.css"] }); }); it("should parse a components inputs", function () { expect(parser_1.default(component_1).inputs).toMatchObject([{ description: "boolean type\nwith second line", name: "disabled", type: "boolean", value: false, }, { description: "string type", name: "name", type: "string", value: "test" }, { description: "number type", name: "count", type: "number", value: 1 }, { description: "string literal types", name: "type", type: "string", options: ["primary", "secondary"], value: "primary" }, { description: "numeric literal types", name: "type", type: "number", options: [1, 2, 3], value: 1 }, { description: "variant types", name: "what", type: "any", value: "test" }, { description: "no default", name: "empty", type: "string", }, { description: "non primitive", name: "hero", type: "Hero", value: "Superman" }]); }); it('should parse a components outputs', function () { expect(parser_1.default(component_1).outputs).toMatchObject([{ description: "output property", name: "onClick", value: "new EventEmitter<boolean>()", }]); }); }); describe("Parser Component 2", function () { it("should parse a component decorator", function () { expect(parser_1.default(component_2).component).toMatchObject({ name: "SampleComponent", template: "<h1>Test</h1>", styles: [ 'h1 { font-weight: normal; }' ] }); }); it("should parse a components inputs", function () { expect(parser_1.default(component_2).inputs).toMatchObject([ { name: "disabled", type: "boolean", value: false } ]); }); it("should parse a components outputs", function () { expect(parser_1.default(component_2).outputs).toMatchObject([]); }); }); //# sourceMappingURL=parser.test.js.map