-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"conn.transaction is not a function" with MSSQL #95
Comments
I have the same issue. My current workaround is to create my own implementation of the mock spec: import Promise from 'bluebird'
import _ from 'lodash'
// tslint:disable: no-submodule-imports
// @ts-ignore
import { spec } from 'mock-knex/dist/platforms/knex/0.11'
// @ts-ignore
import { makeClient } from 'mock-knex/dist/platforms/knex/0.8'
// tslint:enable: no-submodule-imports
// tslint:disable-next-line: no-namespace
namespace MSSQLMockKnex {
class MockTransaction {
public async begin() {
return this
}
// tslint:disable: no-empty
public async commit() {}
public async request() {}
public async rollback() {}
// tslint:enable: no-empty
}
interface Connection {
__knexUid: string
timeout: any
transaction: () => MockTransaction
}
const connection: Connection = {
__knexUid: 'mockedConnection',
timeout: Promise.method(getConnection),
transaction: () => new MockTransaction(),
}
function getConnection() {
return { ...connection }
}
export const newSpec = _.defaultsDeep(
{
replace: [
{
client: {
acquireConnection() {
return Promise.resolve(getConnection())
},
// tslint:disable-next-line: no-empty
destroyRawConnection() {},
},
},
],
},
spec
)
export const client = makeClient(newSpec)
} Then to use it: const db = knex({ client: 'mssql' })
MSSQLMockKnex.client.mock(db)
// now you can use db to create mock MSSQL transactions |
I've tried the code you've given with hijaq's code, but I'm still getting this error.
I did try to do this, but the test just goes on never ending land. const connection = {
__knexUid: 'mockedConnection111',
timeout: Promise.method(getConnection),
transaction: () => new MockTransaction()
beginTransaction: () => new MockTransaction()
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, first of all, thanks for that useful package! Now the issue... I'm trying to use
mock-knex
with MSSQL (no connection to db) and it fails when I try to calltransaction
method, here's a sample code to reproduce:and the error is:
used version:
6.3.0
5.1.0
0.19.3
0.4.6
The text was updated successfully, but these errors were encountered: