I am using jest and typescript and I want to test some code that is using winston logger as dependancy. I am struggling with the type I should expect from jest.doMock
Here is an extract of my setup.
describe('Logger unit tests', () => {
let getLogger: GetLogger
let winston: jest.Mocked<any>
beforeEach(() => {
jest.doMock('winston', () => ({
config: {
syslog: {
levels: {
info: 3,
},
},
},
createLogger: jest.fn(),
format: {
colorize: jest.fn(),
combine: jest.fn(),
json: jest.fn(),
label: jest.fn(),
printf: jest.fn(),
splat: jest.fn(),
timestamp: jest.fn(),
},
transports: {
Console: jest.fn(),
},
}))
winston = require('winston')
})
})
It is fine, tests are passing, typescript is not complaining but I would love to remove the any in let winston: jest.Mocked<any> but I don't know what I should put.
I tried stuffs like
import * as Winston from 'winston'
describe('Logger unit tests', () => {
let getLogger: GetLogger
let winston: jest.Mocked<typeof Winston>
...
But I have types error like this one.
Typescript does not consider that nested methods are jest function
How can I achieve that ?
