jjzjj

andReturn

全部标签

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 - 如何解决TypeError : spyOn andReturn is not a function?

我正在尝试为服务运行jasmine单元测试。我模拟了$location但出现错误:app.factory('testService',function($location){return{config:function(){varhost=$location.absUrl();varresult='';if(host.indexOf('localhost')>=0){return'localhost'}if(host.indexOf('myserver')>=0){return'myserver'}}};});我的测试是这样的:describe('testingservice',fun

php - 更新 mockery 的 andReturn

我能以某种方式更新特定shouldReceive的shouldReturn值吗?例如,我有几个使用一个返回值的测试,只有一个使用其他返回值。所以我把它放在了setUp中:$this->someDependency->shouldReceive('someMethod')->andReturn(0);如果我把它放在那个特定的测试用例中:$this->someDependency->shouldReceive('someMethod')->andReturn(1);它将被忽略并返回0。我“修复”了所有测试的移动模拟并从setUp中移除。但我不喜欢那种代码重复。

java - EasyMock中的 ".andReturn(...).anyTimes()"和 ".andStubReturn(...)"有区别吗?

Thispost建议两者——两者之间存在差异(请参阅用户SnoopyMe的评论)并且两者可以互换使用。EasyMock文档没有提及任何区别。在实践上或语义上有什么区别吗?如果是这样,什么时候使用一个比另一个更合适?编辑:以下测试表明存在差异,至少在与严格模拟一起使用时:@TestpublicvoidtestTestMe(){Barbar=createStrictMock(Bar.class);expect(bar.doBar()).andReturn(1).anyTimes();expect(bar.doOtherBar()).andReturn(2).once();replay(ba

java - 什么是 Mockito 等价于 expect().andReturn().times()

我一直在试验Mockito的等价物EasyMock.expect(someMethod()).andReturn(someMockObject).times(n);但我想不通。请提供一点帮助,好吗?提前致谢。 最佳答案 when(myObject.someMethod()).thenReturn(someMockObject);//runtestverify(myObject,times(n)).someMethod();参见documentation获取更多转换示例。 关于java-什