Karma单元测试不能序列化循环结构

时间:2016-11-29 10:14:41

标签: angularjs unit-testing karma-runner stringify

我正在使用Karma为我的角度代码编写单元测试。我有以下测试失败:

it('handles a successful log in', function() {
    $scope.login(user);

    deferred.resolve({data: {data: {id: 1}}});
    $scope.$apply();

    //expect(api.post).toHaveBeenCalledWith('authentication/login', user, true);
    //expect(api.get).toHaveBeenCalledWith('hd/permissions');
    //expect($state.go).toHaveBeenCalled();
});

这是我得到的错误:

Running "karma:unit" (karma) task
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
    TypeError: JSON.stringify cannot serialize cyclic structures.
    at c:/Users/mabj/AppData/Local/Temp/node_modules/core-js/modules/es6.symbol.js:224:0 <- C:/Users/mabj/AppData/Local/Temp/a3d3ad3841dd260581022edde320b394.browserify:83092

但是,如果我将代码中的第四行更改为deferred.reject({data: {data: {id: 1}}});,则测试成功。使用Apple计算机开发团队的人员也可以毫无失败地运行此测试。我的团队中没有人知道为什么它在我的电脑上失败了。

这里有没有人知道它失败的原因或者我可能尝试做什么让它成功?

0 个答案:

没有答案