https://github.com/natlibfi/oracledb-mock-js
A mock for oracledb Node.js module
https://github.com/natlibfi/oracledb-mock-js
Last synced: 4 months ago
JSON representation
A mock for oracledb Node.js module
- Host: GitHub
- URL: https://github.com/natlibfi/oracledb-mock-js
- Owner: NatLibFi
- License: lgpl-3.0
- Created: 2020-06-23T04:29:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-22T10:12:22.000Z (over 2 years ago)
- Last Synced: 2025-07-01T20:03:28.749Z (about 1 year ago)
- Language: JavaScript
- Size: 449 KB
- Stars: 3
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# A mock for oracledb Node.js module [](https://npmjs.org/package/@natlibfi/oracledb-mock)
# Usage
```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 `.*`.
- **expectedArgs**: An optional object which, if present, must be equal to the arguments passed to the execute-call of the connection.
- **results**: An array of results represented as object (Column names are the properties).
## License and copyright
Copyright (c) 2020 **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.