Cannot inject service into its Angular unit test

你。 提交于 2019-12-06 12:33:04

I've figured out the problem. It seems that one of the Angular module dependencies was not included by Karma, which caused the 'inject' to not work.

Try injecting an instance of your service inside each it() method.

eg:

it('should be injected', inject(function ('MyService') {
        console.log(deferred);
        expect(MyService).toBeDefined();
    }));

    describe('method', function () {
        it('should have this method', inject(function ('MyService') {
            expect(MyService.method).toBeDefined(); 
            expect(typeof MyService.method).toBe('function');
        }));
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!