DI如何实例化转换(ui-router-ng2)?

时间:2017-04-25 03:31:23

标签: angular angular-ui-router angular-ui-router-extras

我正在玩ui-router-ng2。当单元测试具有Transition依赖性的组件以获取查询字符串时遇到了一些问题。

然后我通过这个模块的代码来了解如何在我的测试套件中使用Jasmine注入此实用程序的适当方法。

到目前为止,我还没有找到任何由ui-router-ng2公开的工厂类,它们负责创建Transitions。  有一个提供工厂方法的transitionService,但我不确定这是我正在寻找的,以及如何在我的测试模块设置中利用它。

问这个是因为我在运行我的测试套件时遇到了“No Provider for Transition”错误,这里是伪代码:

 import {APP_BASE_HREF} from "@angular/common";
import {TestBed, async, inject} from "@angular/core/testing";
import {AppModule} from "../index";
import {Observable} from "rxjs";
import {StateService, Transition} from "ui-router-ng2";
import {XXComponent} from "./XXX.component";
describe('XXComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
{provide: APP_BASE_HREF, useValue: '/'}
],
imports: [
AppModule
]
});
TestBed.compileComponents();
}));

it('should complete XXX', async(inject(
[StateService, Transition, XXComponent], (service, transition, component) => {
let oId="823";
let aId ="123";
spyOn(transition, 'params').and.returnValue({'oId': '823', 'aId': '123'});
spyOn(stateService, 'go').and.stub();
... })));
})

任何意见将不胜感激。

0 个答案:

没有答案
相关问题