Search code examples
angularunit-testingkarma-jasminekarma-coverage

Not able to increase code coverage in Angular Unit testing


I am trying to learn how to make unit testing for Angular with Karma and Jasmine.

My problem is that I make it with spyOn() and expect.toHaveBeenCalled() and even though Karma says that passed the tests, the Code Coverage is not updated.

I am new to angular unit testing and I dont know how to test methods properly so as to get code coverage.

Thanks everyone for the help.


Solution

  • spyOn(EnvironmentService, 'isProduction'); overwrites the service method and then EnvironmentService.isProduction(); is calling a spy instead of your method. Thus your method isn't called. valid test would be removing spy and will looke in some way like expect(EnvironmentService.isProduction()).toBe(false)