You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a lambda which calls an interface. Am trying to mock the functions imported from the interface. In each test case, I have to mock different values. When I run all the test cases, the first mocked value does not get cleared and it is carried over to all Test cases
interface.js
const oracledb=require("oracledb");
module.exports = class dbLayer{
execSql= async (sqlQuery) => {
var result;
var binds={};
result = await oracledb.execute(sqlQuery,binds);
return result
}
}
lambda.js
const qryInterface = require(./interface)
var db;
const handler = async (event, context) => {
var sql= event.query
db = new qryInterface();
var dbResponse = await db.execSql(sql)
return dbResponse
}
Test 1 mocks the value set in firstQryResponse and Test 2 mocks secondQryResponse. But what happens is the value mocked for execSql is Not getting reset in Test 2 .i.e. firstQryResponse gets carried over to Test 2. Because of this, 2nd test fails. If i run them individually, it runs fine. I did try mockReset(), but it does not help as well.
Also what i noticed was, even if i dont do any mocks in Test 2, the mocks I did in Test 1 gets carried over.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a lambda which calls an interface. Am trying to mock the functions imported from the interface. In each test case, I have to mock different values. When I run all the test cases, the first mocked value does not get cleared and it is carried over to all Test cases
interface.js
lambda.js
test.js
Test 1 mocks the value set in firstQryResponse and Test 2 mocks secondQryResponse. But what happens is the value mocked for execSql is Not getting reset in Test 2 .i.e. firstQryResponse gets carried over to Test 2. Because of this, 2nd test fails. If i run them individually, it runs fine. I did try mockReset(), but it does not help as well.
Also what i noticed was, even if i dont do any mocks in Test 2, the mocks I did in Test 1 gets carried over.
Appreciate any help on this
Thanks
Sadiq
Beta Was this translation helpful? Give feedback.
All reactions