-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8f167f
commit 849acb4
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# fake-knex-client | ||
|
||
Fake Client for Knex.js | ||
|
||
## Usage | ||
|
||
```typescript | ||
import * as knexpkg from 'knex'; | ||
import mockKnex from 'mock-knex'; | ||
import { FakeClient } from '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. |