Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myrotvorets/fake-knex-client
Fake Client for Knex.js
https://github.com/myrotvorets/fake-knex-client
Last synced: 4 days ago
JSON representation
Fake Client for Knex.js
- Host: GitHub
- URL: https://github.com/myrotvorets/fake-knex-client
- Owner: myrotvorets
- License: mit
- Created: 2023-09-20T04:45:12.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-11T22:16:37.000Z (12 days ago)
- Last Synced: 2024-12-11T23:22:21.096Z (12 days ago)
- Language: JavaScript
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fake-knex-client
Fake Client for Knex.js
## Usage
```typescript
import * as knexpkg from 'knex';
import mockKnex from 'mock-knex';
import { FakeClient } from '@myrotvorets/fake-knex-client';describe('...', function () {
let db: knexpkg.Knex;before(function () {
const { knex } = knexpkg.default;
db = knex({ client: FakeClient });
mockKnex.mock(db);
});// ...
});
```## Why
We discovered that our integration tests, which involve a real database,
don't work smoothly alongside our functional tests that use `mock-knex`
with the actual database driver when we employ `mocha` as our test runner.
This issue likely arises because `mocha`, unlike `jest`, doesn't isolate each test,
resulting in some unexpected behavior.One potential solution we considered was to utilize a distinct database driver
for functional tests, such as `better-sqlite3`. However, this approach
would introduce a significant and unnecessary dependency to our project.