Expected a spy, but got Function

前端 未结 3 998
臣服心动
臣服心动 2020-12-10 10:37

I am trying to implement a test (1) for this module (2).
My purpose is to check if the collection is fetched when a particular event is triggered.
As you can see fr

3条回答
  •  被撕碎了的回忆
    2020-12-10 11:04

    You need to get into the actual method, which in this case is on the prototype.

    describe('When onGivePoints is fired', function () {
        beforeEach(function () {
            spyOn(UsersBoardCollection.prototype, 'restartPolling').andCallThrough();
            app.vent.trigger('onGivePoints');
        });
        it('the board collection should be fetched', function () {
            expect(UsersBoardCollection.prototype.restartPolling).toHaveBeenCalled();
        });
    });
    

    Spying on the prototype is a nice trick you can use when you can't get to the actual instance you want to spy on.

提交回复
热议问题