How DI Instantiate Transition(ui-router-ng2)?

620 Views Asked by At

I'm playing with ui-router-ng2. And encountered a couple of problems when unit testing components having dependency of Transition for obtaining query strings.

And then I went though the code of this module to see how's the appropriate way to inject this utility inside my test suites with Jasmine.

So far, I haven't found any factory classes exposed by ui-router-ng2 that's responsible for creating Transitions. There's a transitionService providing a factory method but I'm not sure if that's what I'm look for and how to leverage this in my test module setup.

Asking this because I got error of 'No provider for Transition' when running my test suites and here's the pseudo code:

 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();
... })));
})

Any comments will be appreciated.

0

There are 0 best solutions below