Here is my function which will return a promise once it gets data from oracle database:
const getDataFromOracleDB = (filter, query) =>
new Promise(async (resolve, reject) => {
let conn;
try {
conn = await oracledb.getConnection(dbConfig);
const result = await conn.execute(query, [filter]);
const { rows } = result;
...
catch (err) {
...
}
};
As the unit test, I want to stub conn.execute
, but have no idea how to do that. I've treid:
const stub = sinon.stub(conn, 'execute').returns([1, 2, 3]);
But got:
TypeError: Cannot stub non-existent own property execute
Any suggestions?
I can't replicate the error with the code you supplied, but perhaps this quick mockup will help:
The query would normally return a value of 1, but this returns 2 and passes.