From 849acb473827fc25ffdc98dce7f818c716c0191a Mon Sep 17 00:00:00 2001 From: Unsung Hero <66092015+myrotvorets-team@users.noreply.github.com> Date: Wed, 20 Sep 2023 08:14:09 +0300 Subject: [PATCH] Create README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5518332 --- /dev/null +++ b/README.md @@ -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.