mardi 30 août 2016

Angular2 Unit Test With Router

Using 2.0.0-rc.4 at the moment, trying to unit test a component that contains the router. The way I used to handle the router doesn't seem to work anymore and I'm getting some strange errors when I try to run my tests. Has anyone managed to get the router injected unit tests working in rc.4 or should I wait until I have fully upgraded my app to rc.5 and fix it then?

My Code:

describe('Component', () => {
    let activatedRoute: ActivatedRoute;
    let component: Component;
    let router: Router;

    beforeEach(() => {
        addProviders(() => [
            Component,
            provide(Router, { useValue: jasmine.createSpyObj('Router', ['navigate'] })
        ]);
    });

    beforeEach(inject([ Component, Router, ActivatedRoute ], (_component, _router, _activatedRoute) => {
        component = _component;
        router = _router;
        activatedRoute = _activatedRoute;
    });

    describe('On Initialisation', () => {

        it('should return true (dummy test)', () => {
            expect(true).toBe(true);
        });

    });
});

When I run this test, it gives me the following error in my powershell:

_instantiateProvider@D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:29099:38 <- webpack:///~/@angular/core/src/di/reflective_injector.js:636:0
 _new@D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:29088:42 <- webpack:///~/@angular/core/src/di/reflective_injector.js:625:0
get@D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:29049:31 <- webpack:///~/@angular/core/src/di/reflective_injector.js:586:0
D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:38201:75 <- webpack:///~/@angular/core/testing/test_injector.js:55:46
map@[native code]
execute@D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:38201:33 <- webpack:///~/@angular/core/testing/test_injector.js:55:0
D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:38295:63 <- webpack:///~/@angular/core/testing/test_injector.js:149:28
_instantiate@D:/Dev/BPO-Starter-Pack/config/spec-bundle.js:29225:98 <- webpack:///~/@angular/core/src/di/reflective_injector.js:76

Version Information:

Typescript: 1.8 Angular: 2.0.0-rc.4 npm: 3.10.6 node: 6.4.0

Aucun commentaire:

Enregistrer un commentaire