I am trying to mock knex using jest for below implementation
const knex = Knex({ client: "mysql"})
const query = knex("table_name")
.where({
title: "xxx-yyy",
lang: "eng"
})
.select()
.orderBy('date', 'desc')
.toSQL()
.toNative()
Below I tried but it didn't work and getting error "TypeError: knex is not a function"
jest.mock("knex", () => {
return () => {
return {
knex: () => {
where: () => {
select: () => {
orderBy: () => {
toSQL: () => {
toNative: jest.fn()
}
}
}
}
}
}
}
})
I really appreciate any help on this please.