Evabila
Evabila

Reputation: 25

TypeError: Cannot read property 'injector' of null

I have gotten this error message «TypeError: Cannot read property 'injector' of null» when I run unit tests in jasmine and angular 2 RC5.

My unit test code is :

describe('Test of category services', () =>{

beforeEach(() => {

                    TestBed.configureTestingModule({
                                providers: [CategoryService ]
                            });
                });

    it('1. Add a new category', inject([CategoryService], (categoryService )  =>{


        categoryService.addCategory(category)
            .subscribe(res => {
                    expect(CATEGORY.codeCategory).toBe(res.codeCategory);
                    expect(CATEGORY.name).toBe(res.name);
                    expect(CATEGORY.taxPercentage).toBe(res.taxPercentage);
                    expect(CATEGORY.description).toBe(res.description);
                    expect(res.idCategory).toBeGreaterThan(0);
                }

            );
    }));

});

After spending many hours looking for a solution, I decided to ask for any help.

Thank you

Upvotes: 2

Views: 2934

Answers (2)

Evabila
Evabila

Reputation: 25

After updating angular for the last version (2.0.0), I have no longer this error message. Thanks you all for your help !

Upvotes: 0

Mark Acosta
Mark Acosta

Reputation: 330

I dont know the problem with your code, but I do know that error usually means that you are providing an injection that isnt being passed through the providers or the constructor correctly. Essentially, its not serving the injection at the location where you are using it. Sorry i cant be of more help.

What i can decipher, is that you are providing the service you are testing and using inject, i assume u are importing the inject library already but instead do you have the @Injectable() decorator in your service?

Upvotes: 1

Related Questions