我在我的node.js应用程序中有一个JS方法,我想进行单元测试.它对服务方法进行多次调用,每次都将该服务传递回调; 回调累积结果.
我如何使用Jasmine来删除服务方法,以便每次调用存根时,它都会使用由参数确定的响应来调用回调?
这是(就像)我正在测试的方法:
function methodUnderTest() {
var result = [];
var f = function(response) {result.push(response)};
service_method(arg1, arg2, f);
service_method(other1, other2, f);
// Do something with the results...
}
Run Code Online (Sandbox Code Playgroud)
我想指定当使用arg1和arg2调用service_method时,存根将使用特定响应调用f回调,并且当使用other1和other2调用它时,它将使用不同的特定响应调用相同的回调.
我也考虑一个不同的框架.(我尝试过Nodeunit,但没有按照我的意愿去做.)