jjzjj

javascript - Jasmine spy 期望用 "Object(...)"调用

我正在完成从Jasmine1.3到2.0的迁移。到目前为止,我已经重构了大部分代码以符合2.0的更新语法。然而,某种测试仍然失败。简而言之,我的测试是这样的:varobj=newCustomCriteria();spyOn(my,"function");my.function(obj);expect(my.function).toHaveBeenCalledWith({big:"fatobject"});我的CustomCriteria类:varCustomCriteria=function(){this.big="fatobject";};测试失败,出现以下情况:Expectedsp

javascript - 试图监视(Jasmine)Array.prototype 方法导致堆栈溢出

这很奇怪。将testemrunner与jasmine2一起使用并执行以下规范(尽管它正确地标记了没有期望):describe('Spyingonarray.prototypemethods',function(){it('shouldworkthisway',function(){spyOn(Array.prototype,'push').and.callThrough();//expect(1).toBe(1);});});但是,添加一个expect(任何expect!)它会导致堆栈溢出,并在testem控制台中显示以下消息:RangeError:超出最大调用堆栈大小。在http:/

javascript - 如何在 Jest 中监视 window.scrollTo?

我得到了一个非常简单的React组件,具有以下功能:componentDidMount(){window.scrollTo(0,0)}看来你不能做类似的事情window.scrollTo=jest.fn()监视scrollTo函数。因此,我想知道监视此函数并断言它已在我的测试中使用过的最佳方法是什么。谢谢 最佳答案 开个Jest,全局namespace必须通过global而不是window访问。global.scrollTo=jest.fn() 关于javascript-如何在Jest中

javascript - QUnit、Sinon.js 和 Backbone 单元测试受挫 : sinon spy appears to fail to detect Backbone Model event callbacks

在下面的单元测试代码中:TestModel=Backbone.Model.extend({defaults:{'selection':null},initialize:function(){this.on('change:selection',this.doSomething);},doSomething:function(){console.log("Somethinghasbeendone.");}});module("Test",{setup:function(){this.testModel=newTestModel();}});test("intra-modeleventbi

javascript - WebStorm 中的 Spy-JS 未捕获

我正在使用带有Spy-js集成的WebStorm8(更多http://blog.jetbrains.com/webstorm/2014/04/spy-js-webstorm-secret-service/)当我从IDE运行配置运行SpyJS时,我无法让它捕获请求当我通过本地代理模式访问URL时,http://localhost:3546/?spy-js=localhost:9000它有效,但有其局限性...(更多https://github.com/spy-js/spy-js#local-proxy)系统代理似乎配置正确:http://localhost:3546/spy-js-pro

javascript - 如何通过 Jasmine spy 将被拒绝/失败的 promise 返回到单元测试中的 Angular Controller

我正在使用jasmine来测试我的AngularController。我在.then(successCallback,errorCallback)中捕获错误和成功虽然它在实时功能的基础上运行良好,但我很困惑如何编写一个spy来返回错误,因为它总是在successCallback()中被捕获以下是Controller:-angular.module('myApp').controller('LoginCtrl',function($scope,$location,loginService,SessionService){$scope.errorMessage='';$scope.logi

javascript - Jasmine Controller 测试,预计 spy 已被调用

我在AngularJSController中定义了一个方法,该方法在初始化时调用。我想使用Jasmine("jasmine-core":"^2.3.4","karma":"^0.12.37")测试它。我遵循了Internet上的一些教程和StackOverflow问题,但找不到正确的答案。请看一下这段代码:ControllerusersAddUserController:(function(){'usestrict';angular.module('app.users.addUser').controller('usersAddUserController',['$scope','us

javascript - 为什么 Jasmine spy 不认为它被调用,即使它返回了 andReturn 值?

我正在尝试调试jQuery.post上的spy程序那没有开火,所以作为完整性检查,我试过了spyOn(this.viewModel.requests,'submitRequest').andReturn('fooz');varret=this.viewModel.requests.submitRequest();expect(ret).toEqual('foo');expect(this.viewModel.requests.submitRequest).toHaveBeenCalled();这失败了Expected'fooz'toequal'foo'.但是当我在andReturn的参

javascript - 使用 sinon spy restore 或 reset 的正确方法是什么?

我有一套带有mocha、sinon和chai的测试服:describe('generalvisormethodstests',()=>{letres,req,next,resSpy,resNext;beforeEach(()=>{res={};next=()=>{};resSpy=res.json=sinon.spy();resNext=next=sinon.spy();});afterEach(()=>{resSpy.restore();resNext.reset();});describe('getbasemaplayersfromownermodel',()=>{it('shou

javascript - Chrome - 中断属性修改

我想在类属性被脚本更改时中断。我尝试了“Breakon:attributemodificationsbutitdoesn'tbreak.” 最佳答案 通常Chrome的Breakon功能应该可以正常工作,如果没有,您可以使用以下方法:解决方法以下代码仅在您的浏览器支持MutationObserver时才有效.使用F12打开开发者工具并在控制台中执行以下代码:varSpy=/**@class*/(function(){functionSpy(){}Spy.observe=function(targetNode){Spy.observe