A mock for oracledb Node.js module
js
import createMock from '@natlibfi/oracledb-mock';const oracledb = createMock();
oracledbMock._execute([
{
queryPattern: /^SELECT * from foobar$/,
results: [
{ foo: 'bar' }
]
}
]);
await operate(oracledbMock);
oracledbMock._clear();
async function operate(oracledb) {
const connection = await oracledb.getConnection();
const {resultSet} = await connection.execute('SELECT * from foobar');
const row = await resultSet.getRow();
// do something with
{foo: 'bar'}
return connection.close();
}
`
Mocking queries
The _execute method initializes the mock with expected queries and their results. An array of object is passed to the _execute method and the array is iterated for matching results. The following parameters are supported
- queryPattern: A RegExp object which the query is tested against. Defaults to .*`.Copyright (c) 2020, 2026 University Of Helsinki (The National Library Of Finland)
This project's source code is licensed under the terms of GNU Lesser General Public License Version 3 or any later version.