javascript - How to unit test function having global variable using Chai Mocha and sinon? -
consider function,
function upgradeplans (arr, curplan) { var ispaidcustomer = cust && cust.type === "subscriber" && cust.subtype === "paid"; (var = 0, max = arr.length ; < max ; i++) { if (ispaidcustomer) { if (plans_index[arr[i].plansize] > curplan)) { arr[i].upgradeplan = true; } continue; } break; } return arr; }, in function, cust , plans_index global object, test not have access these.
now, want unit test function e.g
- it returns
arrwhencustnot defined - it returns
arrwhencustnot subscriber - it returns
arrwhencustnot paid subscriber
to solve this, tried change upgradeplans function way,
function upgradeplans (arr, curplan, cust, plans_index) { // same content above function } to test function having global variable, have pass variable argument.
this solves problem requires lot of changes in code.
is there other way test above function without changing in code ?
Comments
Post a Comment