Why mi jasmine spec fails TypeError: undefined is not a constructor (evaluating 'this.sortLayout.$('.toggle').removeProp('disabled')')?

Why mi jasmine spec fails TypeError: undefined is not a constructor (evaluating 'this.sortLayout.$('.toggle').removeProp('disabled')')?

当我测试这部分代码时,jasmine 向我发送此错误 TypeError: undefined is not a constructor (evaluating 'this.sortLayout.$('.toggle').removeProp('disabled')')

 onResponsive: function() {
        var selectedServers,
            spanDetails,
            span;
        this.sortLayout.$('.toggle').removeProp('disabled');
        this.contractYear.$('.toggle').removeProp('disabled');
        selectedServers = parseInt(this.sortLayout.$('.toggle').find('span').text().match(/\d+/)[0], 10);
        span = $('div.wrapper').find('span');
        spanDetails = $('div#divider').find('span');

        span.empty();
        spanDetails.empty();
        if(selectedServers === 1){
            span.append('Selected '+selectedServers);
        }else{
            spanDetails.append('Selected'+selectedServers);
        }

    }

规格

describe('#onResponsive', function() {
        it('enables sort filter menu', function() {
            this.view.onShow();
            spyOn($.fn, 'removeProp');
            spyOn($.fn, 'find').and.returnValue('4');
            this.view.onVizResponsive();
            //var result = $('.dropdown-toggle').find();
            //expect(result).toEqual('4');
            expect($.fn.removeProp).toHaveBeenCalledWith('disabled');
            expect($.fn.removeProp).toHaveBeenCalledWith('span');

        });
    });

当这个 jQuery 函数没有 return 任何东西时,为什么我会失败。

我需要将切换附加到 DOM。

describe('#onResponsive', function() {
            it('enables the sort filter menu', function() {
                this.view.onShow();
                spyOn($.fn, 'removeProp');
                this.view.sortLayout.$el.append('<button class="toggle" disabled><span>Toggle option 1</span></button>');
                this.view.onVizResponsive();
                this.view.sortLayout.$el.find('.toggle').remove();
                this.view.sortLayout.$el.append('<button class="toggle" disabled><span>Toggle option 2</span></button>');
                this.view.onVizResponsive();
                expect($.fn.removeProp).toHaveBeenCalledWith('disabled');
            });
        });