Open sl-ffx opened 3 years ago
At the moment I'm using following quickfix
const mockBackup = {}
mockBackup._stream = db.client.constructor.prototype._stream
mockBackup._query = db.client.constructor.prototype._query
mockBackup.processResponse = db.client.constructor.prototype.processResponse
mockDb.mock(db)
mockDb.unmock(db)
db.client.constructor.prototype._stream = mockBackup._stream
db.client.constructor.prototype._query = mockBackup._query
db.client.constructor.prototype.processResponse = mockBackup.processResponse
Hey, I'm having a similar issue with knex >= v0.95
, but thanks to the @sl-ffx I was able to fix it.
Is there anyone who can actually fix it in mock-knex
?
I opened an MR to fix this. If you want to monkey-patch it yourself, you can use this code (tested only with v0.4.11)
const transformer = Object.getPrototypeOf(require("mock-knex/dist/util/transformer"));
const _lodash2 = {default:require("lodash")}; // needed by the new function
const newFn = transformer._replace.toString()
.replace(".replace('._constructor.', '.constructor.')", ".replace('._constructor.', '.constructor.').replace('._prototype.', '.prototype.')")
.replace(".replace('.constructor.', '._constructor.')", ".replace('.constructor.', '._constructor.').replace('.prototype.', '._prototype.')");
transformer._replace = eval("(" + newFn + ")");
We only started experiencing this error when we introduced semantic-release
(versions 9 and later) as a dependency in our project. The fix in #138 solved the issue for us. Thanks @danthegoodman !
The
unmock
method does not work as expected. I would expect to have the original client working as it would never have been mocked. Afterunmock
the client always throw an error on executing a query:I'm using mock-knex v0.4.9 knex v0.21.19
Here is a code example to get the error
If you remove the
mock
andunmock
lines the query works.