I have a problem. I'm setting up an anonymous function
let getLisMock = sinon.mock();
GetListMock.calledWith({data: 'data'});
The function I'm testing
function someFunc({data: 'data'}, callback) {
async.retry({times: 3,interval: 10}, function(callback){
getList({data: 'data'}, callback); },
callback)
}
I combine someFunc and getList with rewire and __set__
The settings of sinon before the function is called look like this
GetListMock.onCall(0).yields(new Error('error'), null);
GetListMock.onCall(1).yields(null, {items: [{id: 1}]});
Next, call the function and expect.
Whatever I do I get an error: Uncaught ExpectationError: Anonymous mock already called once
PS Sorry for the question in this format, I don't have access to a computer right now. A little later, if no one answers, I will add a test sample.
I tried making one call with once() and just throwing an error, but in the end all roads led me here.
GetListMock.twice();
GetListMock.onCall(0).yields(new Error('error'), null);
GetListMock.onCall(1).yields(null, {items: [{id: 1}]});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.