TypeError: 'undefined' is not an object (evaluating 'currentSpec.queue.running')

本小妞迷上赌 提交于 2019-12-03 23:06:35

I only have a few minutes right now but I think one of your issues here is that you are trying to test much more than a unit. Unit testing is very specific and simplistic in its purpose. When I do it I try to inject as little as possible and minimize dependencies. In your case, instead of having one test suite for this I think you should have a suite for each one. Try something more like this:

describe('DateFactory unit tests', function() {    
    beforeEach(module('clientApp'));


    describe("when getting a visible date range", function() {
        beforeEach(inject(function(dateFactory) {
            spyOn(dateFactory, 'getVisibleDateRange').andReturn(2013);
        }));

        it('should be 2013', inject(function(dateFactory) {
            expect(dateFactory.getVisibleDateRange(param1, param2, param3)).toBe(2013);
        }));
    });
});

describe('LessonPlannerFactory unit tests', function() {
    var data, lessonPlannerFactory;

    beforeEach(module('clientApp'));

    describe('When creating daily periods', function() {
        var query = "your visible date range";

        beforeEach(inject(function(lessonPlannerFactory) {
            spyOn(lessonPlannerFactory, 'createPeriodsDaily').andReturn(query);
        }));

        it('Should be the visible date range', inject(function(lessonPlannerFactory) {
            expect(lessonPlannerFactory.getVisibleDateRange()).toBe(query);
        }));
    });
});

I hope that helps out a bit.

Jordan

This one solves my issue:

try to change isSpecRunning function on angular-mocks.js

function isSpecRunning() {
    return currentSpec && currentSpec.queue && currentSpec.queue.running
        || currentSpec; // for Mocha.
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!