Inject $log service on simple Jasmine test

天涯浪子 提交于 2019-12-22 18:18:48

问题


Yes, I'm completely new to Angular and Jasmine, and I can't figure out how to inject a mock $log for my test. This is the test:

(function () {
    'use strict';

    describe('basic test', function(){
        it('should just work', function(){
            var $log;

            beforeEach(inject(function(_$log_){
                $log = _$log_;
            }));

            $log.info('it worked!');
            expect($log.info.logs).toContain(['it worked!']);
        });
    });

}())

This fails on the inject line with an error:

TypeError: Cannot set property 'typeName' of undefined

What am I missing?


回答1:


How's this:

describe('basic test', function(){
    var log;
    beforeEach(inject(function(_$log_){
        log = _$log_;
    }));

    it('should just work', function(){
        log.info('it worked!');
        expect(log.info.logs).toContain(['it worked!']);
    });
});


来源:https://stackoverflow.com/questions/21119013/inject-log-service-on-simple-jasmine-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!