Jasmine - 间谍函数内的函数调用

时间:2017-11-17 08:44:56

标签: angularjs karma-jasmine sinon sinon-chai

作为测试的新手,我做了一些愚蠢的假设,因此我的测试用例没有运行。

我的拦截器工厂看起来像:

public function getFriendsWithMe()
{
    return new ArrayCollection(
        array_merge(array_merge($this->friendsWithMe->toArray(), $this->myFriends->toArray()))
    );
}

现在测试一下,我写道:

angular.module('svcs')
    .factory('authorizationInterceptor', function ($q) {
        var myserver = '',
             serverType = '';
        var myActionTransformer = function (config) {
            .....
            .....
            return ...;
        };
        return {
            responseError: function (response) {
                if (response.status === 403) {
                    console.log('Res : ',response);
                    response.data = 'You are not authorized to ' +
                        myActionTransformer(response.config);
                }
                return $q.reject(response);
            }
        };
    });

Jasmine describe.only('svcs', function () { var authorizationInterceptor,authorizationInterceptorSpy,$q,actionTransformerSpy; beforeEach(function () { module('svcs'); inject(function (_authorizationInterceptor_,_$q_) { authorizationInterceptor = _authorizationInterceptor_; $q = _$q_; }); }); describe('authorizationInterceptor', function () { beforeEach(function () { sinon.spy(authorizationInterceptor, 'responseError').andCallThrough(); actionTransformerSpy = sinon.spy(authorizationInterceptor, 'myActionTransformer'); }); afterEach(function () { authorizationInterceptorSpy.restore(); }); it('should call actionTransformerSpy', function () { authorizationInterceptor.responseError({ code: 403}); expect(actionTransformerSpy).to.be.called; expect(actionTransformerSpy).calledOnce; }); }); ,这正是我想要测试的。

我收到CallThrough() is not working and it's not calling myActionTransformer

我是新手。 请帮忙解释一下。

0 个答案:

没有答案
相关问题