I'm trying to mock an existing API using sinon.
I instantiate my mock like this:
if (typeof nlapiLogExecution === "undefined" || nlapiLogExecution === null) {
nlapiLogExecution = sinon.stub();
}
Then, in my test, I execute this code:
var spy = sinon.spy(nlapiLogExecution);
OrderRenewal.run();
console.log("count = " + spy.callCount);
console.log("count = " + spy.withArgs("DEBUG", "Sales Order Auto-Renewal", "Item auto-renewal completed, processing 3 items.").callCount);
I have two spy.callCounts, and they both return zero (0). You will see that I have tried it both generically and with the exact arguments I am expecting. I am certain that the function is being executed because the code in question is this:
if (!Utility.objectIsNullOrUndefined(accountSettings)) {
var ordersProcessed = processOrders(accountSettings.RenewedSalesOrderStatus, accountSettings.NumberOfPreceedingDays);
console.log("ordersProcessed = " + ordersProcessed);
// Log the completion.
nlapiLogExecution("DEBUG", "Sales Order Auto-Renewal", "Item auto-renewal completed, processing " + ordersProcessed + " items.");
}
And my output is this:
ordersProcessed = 3
count = 0
count = 0
showing that the "ordersProcessed" console.log line is being executed.
Can anyone tell me what I'm doing wrong with the sinon.spy? I've used this feature in other tests and it appears to have worked there.
Thanks,
V
Aucun commentaire:
Enregistrer un commentaire