我目前面臨一個問題,即我有一個基于我的激活路由的 paramMap 的 Observable
this.current$ = this.route.paramMap.pipe(map(paramMap => paramMap.get('title')));
它在我的前端作業得很好,但我最近開始使用角度單元測驗,并且我有一個非常基本的測驗要開始。目前僅持有:
beforeEach(() => {
fixture = TestBed.createComponent(BannerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeDefined();
});
it('should create', () => {
expect(component).toBeDefined();
});
出于某種原因,在運行我的測驗時。以下是錯誤的。
TypeError:無法讀取未定義的屬性“管道”
我有一些其他簡單的測驗設定,但它們都在上述訊息中失敗。我在這里想念什么嗎?
提前致謝。
uj5u.com熱心網友回復:
您可以嘗試像這樣模擬 Route:
``
{
provide: ActivatedRoute,
useValue: {
snapshot: {
paramMap: {
get: (key: string) => {
switch (key) {
case 'title':
return 'my title';
case 'subtitle':
return 'my subtitle'
}
}
},
},
},
}``
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/428576.html
