{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/651","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/651/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/651/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/651/events","html_url":"https://github.com/tgriesser/knex/issues/651","id":55801356,"number":651,"title":"No mock connection available for unit testing","user":{"login":"trevorallred","id":340379,"avatar_url":"https://avatars.githubusercontent.com/u/340379?v=3","gravatar_id":"","url":"https://api.github.com/users/trevorallred","html_url":"https://github.com/trevorallred","followers_url":"https://api.github.com/users/trevorallred/followers","following_url":"https://api.github.com/users/trevorallred/following{/other_user}","gists_url":"https://api.github.com/users/trevorallred/gists{/gist_id}","starred_url":"https://api.github.com/users/trevorallred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevorallred/subscriptions","organizations_url":"https://api.github.com/users/trevorallred/orgs","repos_url":"https://api.github.com/users/trevorallred/repos","events_url":"https://api.github.com/users/trevorallred/events{/privacy}","received_events_url":"https://api.github.com/users/trevorallred/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-28T19:14:54Z","updated_at":"2015-01-28T22:53:58Z","closed_at":null,"body":"I'm trying to unit test my application but I can't find any docs or examples of how to do this. Here's what I'm trying on my config.\r\n\r\n        Knex.knex = Knex.initialize({\r\n            debug: true,\r\n            client: 'mysql',\r\n            connection: {\r\n                host     : 'FAKE_SERVER',\r\n                user     : 'root',\r\n                password : '',\r\n                database : 'integration_tests',\r\n                charset  : 'utf8'\r\n            }\r\n        });\r\n\r\nThen I overwrite the client query:\r\n\r\n        client.query = BluebirdPromise.method(function (builder) {\r\n            var sql = builder.toSql(builder);\r\n            var expectedSql = 'insert into `test_unit` (`id`, `name`) values (?, ?)';\r\n            chai.assert.equal(sql, expectedSql);\r\n            return null;\r\n        });\r\n\r\nI posted this on SO http://stackoverflow.com/questions/28165063/how-can-i-mock-a-fake-database-for-when-unit-testing-against-knex\r\nLater I got it to work on Knex v0.5.0 but when I upgrade to 0.7.3 my unit tests now fail with the following error:\r\n\r\n     Error: getaddrinfo ENOTFOUND\r\n      at errnoException (dns.js:37:11)\r\n      at Object.onanswer [as oncomplete] (dns.js:124:16)\r\n      at Protocol._enqueue (/Users/trevorallred/projects/tantalim/server/node_modules/mysql/lib/protocol/Protocol.js:135:48)\r\n      at Protocol.handshake (/Users/trevorallred/projects/tantalim/server/node_modules/mysql/lib/protocol/Protocol.js:52:41)\r\n      at Connection.connect (/Users/trevorallred/projects/tantalim/server/node_modules/mysql/lib/Connection.js:111:18)\r\n      at /Users/trevorallred/projects/tantalim/server/node_modules/knex/lib/dialects/mysql/index.js:105:16\r\n      at new Promise (/Users/trevorallred/projects/tantalim/server/node_modules/bluebird/js/main/promise.js:82:37)\r\n      at Client_MySQL.acquireRawConnection (/Users/trevorallred/projects/tantalim/server/node_modules/knex/lib/dialects/mysql/index.js:104:10)\r\n      at Object.create (/Users/trevorallred/projects/tantalim/server/node_modules/knex/lib/pool.js:33:19)\r\n      at Object.Pool.createResource (/Users/trevorallred/projects/tantalim/server/node_modules/knex/node_modules/generic-pool-redux/pool.js:288:12)\r\n\r\n\r\nAny better suggestions?"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/71934177","html_url":"https://github.com/tgriesser/knex/issues/651#issuecomment-71934177","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/651","id":71934177,"user":{"login":"trevorallred","id":340379,"avatar_url":"https://avatars.githubusercontent.com/u/340379?v=3","gravatar_id":"","url":"https://api.github.com/users/trevorallred","html_url":"https://github.com/trevorallred","followers_url":"https://api.github.com/users/trevorallred/followers","following_url":"https://api.github.com/users/trevorallred/following{/other_user}","gists_url":"https://api.github.com/users/trevorallred/gists{/gist_id}","starred_url":"https://api.github.com/users/trevorallred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevorallred/subscriptions","organizations_url":"https://api.github.com/users/trevorallred/orgs","repos_url":"https://api.github.com/users/trevorallred/repos","events_url":"https://api.github.com/users/trevorallred/events{/privacy}","received_events_url":"https://api.github.com/users/trevorallred/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T22:53:58Z","updated_at":"2015-01-28T22:53:58Z","body":"I need to do more than check the syntax. I'm trying to unit test the actual query and how it reacts inside my application. How would I mock the entire database? I found this line:\r\nhttps://github.com/tgriesser/knex/blob/master/knex.js#L98\r\n\r\n```javascript\r\nif (config.__client__) {\r\n    client = config.__client__;\r\n}\r\n```\r\nAnd I tried this:\r\n\r\n```javascript\r\nrequire('knex')({\r\n    __client__: function() {\r\n        query: function() {},\r\n        acquireConnection: function() {},\r\n        ...\r\n    }\r\n})\r\n```\r\n\r\nNow when I call `var sql = knex('person')` I get this error:\r\n\r\n    TypeError: undefined is not a function\r\n\r\nI'm pretty sure it's not able to find `function knex(tableName) {`\r\nhttps://github.com/tgriesser/knex/blob/master/knex.js#L66\r\n\r\nAny pointers?"}}