How can I mock a fake database for when unit testing against Knex?
问题 I've been using Knex successfully to connect to a backend database. But I want to be able to unit test my code. Is there a way to mock the database connection? I've tried using proxyquire but I can't seem to get it to work. The problem seems to be with the way Knex is initialized. var knex = require('knex')({ client: 'mysql', connection: {} }); I setup knex to be mocked in my unit test. myService = proxyquire('../app/myService', { 'knex': knexProxy }); My service includes knex. var knex =