加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 2:使用路由器测试组件

发布时间:2020-12-17 08:21:06 所属栏目:安全 来源:网络整理
导读:我正在编写使用routeLink的最简单的组件: @Component({ selector: 'memorySnippet',templateUrl: 'div class="memory-snippet-wrapper" *ngIf="memory" [routerLink]="['MainPanel','MemoryPanel',{'id' : this.memory.id}]"',directives: [CORE_DIRECTIVES
我正在编写使用routeLink的最简单的组件:
@Component({
    selector: 'memorySnippet',templateUrl: '<div class="memory-snippet-wrapper" *ngIf="memory" 
                  [routerLink]="['MainPanel','MemoryPanel',{'id' : this.memory.id}]">',directives: [CORE_DIRECTIVES,ROUTER_DIRECTIVES]
})
export class MemorySnippetComponent {
    @Input() memory: Memory;
}

我尝试测试此组件时会出现此问题.我添加路由器链接Karma的那一刻抱怨缺少提供者:

添加所有提供商后,Karma要求我得到这个:

beforeEachProviders(() => [
    MemorySnippetComponent,MEMORY_SERVICE_PROVIDERS,ROUTER_PROVIDERS,ApplicationRef
]);

但是当我运行测试时,我得到了这个错误:

EXCEPTION: EXCEPTION: Error during instantiation of Token RouterPrimaryComponent! (RouterLink -> Router -> RouteRegistry -> Token RouterPrimaryComponent).

ORIGINAL EXCEPTION: unimplemented

ORIGINAL STACKTRACE:
Error: unimplemented

我究竟做错了什么??? Angular 2(2.0.0-beta.1)还没准备好用路由器指令测试组件吗?

对于带有新路由器的RC4现在使用…
beforeEach(() => addProviders([
  APP_ROUTER_PROVIDERS,// must be first
  {provide: APP_BASE_HREF,useValue: '/'},// must be second
  {provide: ActivatedRoute,useClass: Mock},{provide: Router,useClass: Mock}
]));

使用这种方法的github项目是……

https://github.com/danday74/angular2-coverage

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读