現在、私はAngular 2プロジェクトに単体テストを統合しています。私はサービスをテストすることができますが、外部のテンプレートを取得するためにtemplateUrlを使用しているコンポーネントのテストに問題があります。私は、パス/ディレクトリを間違って解決しているwebpackに関連していると思います。ここに私のテストファイルがあります。Jasmine + Angular2:このテストモジュールでは、 "templateUrl"を使用しているコンポーネントLoginを使用していますが、コンパイルされていません。
import { TestBed, async } from '@angular/core/testing';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { BasePage } from '../../base/base.page';
import { LoginPage } from './login.page';
describe('Page: LoginPage',() => {
let page: LoginPage;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [BasePage, LoginPage],
imports: [ReactiveFormsModule]
});
const fixture = TestBed.createComponent(LoginPage);
page = fixture.componentInstance;
});
it('Page: LoginPage should create a `FormGroup` comprised of `FormControl`s', async(() => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(LoginPage);
page = fixture.componentInstance;
page.ngOnInit();
expect(page).toBeDefined();
expect(page.loginForm instanceof FormGroup).toBe(true);
expect(Object.keys(page.loginForm.controls)).toEqual([
'email', 'password'
]);
});
}));
});
私は、コンソール上の出力は次され、テストを実行している:
WARN [web-server]: 404: /login.page.html
PhantomJS 2.1.1 (Linux 0.0.0) Page: LoginPage Page: LoginPage should create a `FormGroup` comprised of `FormControl`s FAILED
Error: This test module uses the component LoginPage which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test. in spec-bundle.js (line 15105)
私もテンプレートでテンプレートをロードしようとした:生 '(必要./ login.page.html! ')の代わりにtemplateUrl:' login.page.html 'を使用します。しかし、テンプレートの解析エラーのためにテストが失敗する:
Error: Template parse errors:
Unexpected closing tag "h4" (" col-lg-4 offset-lg-4\">\n <h4 class=\"card-title\">{{ 'pages.login.title' | translate }}[
この問題を解決する方法はありますか?