Skip to content

Instantly share code, notes, and snippets.

@GiuseppeMP
Created June 18, 2021 14:25
Show Gist options
  • Save GiuseppeMP/f7015836ceadfd5679e0dc1628480bf8 to your computer and use it in GitHub Desktop.
Save GiuseppeMP/f7015836ceadfd5679e0dc1628480bf8 to your computer and use it in GitHub Desktop.
Como mockar usando jest e type auxiliar
export type MockType<T> = {
[P in keyof T]?: jest.Mock<unknown>;
};
const mockKnexConnection : () => MockType<Knex<any, unknown>>
= jest.fn(() => ({
destroy: jest.fn(() => { console.log }),
raw: jest.fn((query) => {
return new Promise<any>( (res) => {
res(query)
})
})
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment