私は、@angular/material
のタブコントロールを含むAngular2コンポーネントを持っています。Angular2 Material Viewportルーラユニットテストエラー
私は(以下、簡略化のコードを参照してください - 私はこの単純だコンポーネントをテストするにはポイントがありませんことを得る)私のコンポーネントをテストしようとしているし、次のエラーを取得しています:
Error: Error in ./MdTabHeader class MdTabHeader - inline template:0:0 caused by: No provider for ViewportRuler!
Error: No provider for ViewportRuler!
私の仮定がいましたプロバイダとしてViewportRuler(https://github.com/angular/material2/blob/master/src/lib/core/overlay/position/viewport-ruler.ts)を含めるようにしてください。私はこれを行うと、カルマのリターンを(下のコメントアウト行を参照してください):
Uncaught SyntaxError: Unexpected token import
at http://localhost:9876/context.html:10
グーグルのビットから、それはむしろ、コンパイルの.jsよりも、ブラウザに.TSファイルを提供していますことを示唆しています。私は間違った場所から参照している可能性があります。
私の質問は私のテストをコンパイルするには?
私のコードは次のとおりです。
my.component.ts:
@Component({
selector: 'test',
template: require('./test.component.html')
})
export class TestComponent {
items: any[];
constructor() {
this.items = [{ title: 'test 1', description: 'description 1' }, { title: 'test 2', description: 'description 2' }];
}
}
my.component.html:
<md-tab-group>
<md-tab *ngFor="let link of items">
<template md-tab-label>
<h4>{{link.title}}</h4>
</template>
{{link.description}}
</md-tab>
</md-tab-group>
my.component.spec.ts:
import { TestBed } from '@angular/core/testing';
import { Component} from '@angular/core';
import { MaterialModule } from '@angular/material';
import { ViewportRuler} from '@angular/material/core/overlay/position/viewport-ruler'
import { TestComponent } from './test.component';
describe("TestComponent",
() => {
let fixture, component;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [MaterialModule],
declarations: [TestComponent],
providers: [
//{ provide: ViewportRuler }
]
});
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
});
it('true = true',() => {
expect(true).toBe(true);
});
});
私は試しましたできるだけ多くの情報を含めるようにしていますが、私はAngularの世界全体が新しいので、私が提供できるものがあれば教えてください。
多くのありがとうございます。
あなたのテストモジュールで 'MaterialModule.forRoot()'を使ってみましたか?それを修正した@ stealththeninja – stealththeninja
!答えを書くと、私はそれを受け入れるでしょう:) – Alex