How do you test an Angular 2 component here? #1584

Closed
opened 2025-08-09 17:20:46 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @ManuelDeLeon on 6/5/2016

I'm trying to hack my way into testing an Angular 2 component but I think there's got to be an easier way. One without so many errors.

I added mocha and chai, then created the file .\ClientApp\components\app\app.test.ts:

import { App } from './app';
describe("Test", function () {
    it("works", function () {
        let app = new App();
        chai.assert.ok(app);
    });
});

I compile with tsc into a test folder then try to run mocha but get the error reflect-metadata shim is required when using class decorators. After a LOT of trial and mostly errors I find a post that says I should add var reflect = require('reflect-metadata'); to the test file. I do that and now I get Error: Cannot find module './nav-menu.html' Then I tried to add the html files to the test folder but get SyntaxError: Unexpected token <

At this point I think I'm on the wrong path because it shouldn't be this hard. So how do you test an Angular 2 component here?

*Originally created by @ManuelDeLeon on 6/5/2016* I'm trying to hack my way into testing an Angular 2 component but I think there's got to be an easier way. One without so many errors. I added mocha and chai, then created the file `.\ClientApp\components\app\app.test.ts`: ``` js import { App } from './app'; describe("Test", function () { it("works", function () { let app = new App(); chai.assert.ok(app); }); }); ``` I compile with tsc into a test folder then try to run mocha but get the error `reflect-metadata shim is required when using class decorators`. After a LOT of trial and mostly errors I find a post that says I should add `var reflect = require('reflect-metadata');` to the test file. I do that and now I get `Error: Cannot find module './nav-menu.html'` Then I tried to add the html files to the test folder but get `SyntaxError: Unexpected token <` At this point I think I'm on the wrong path because it shouldn't be this hard. So how do you test an Angular 2 component here?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1584
No description provided.