I am pondering how to create mock transports for the File module within the Winston node package. While utilizing Jest, the __mocks__/winston.ts
file is automatically loaded. My dilemma lies in the fact that I am unable to mock it due to the presence of the new
keyword.
// LoggerFactory.ts
import { transports, TransportInstance } from "winston";
...
const transportList: TransportInstance[] = [
new transports.File({
name: `${tag}-error`,
filename: `${dirname}${filename}.error.log`,
json: false,
level: "error",
zippedArchive: false,
maxFiles: 14,
maxsize: 100000000
}),
new transports.File({
name: `${tag}-info`,
filename: `${dirname}${filename}.log`,
json: false,
level: "info",
maxFiles: 10,
zippedArchive: false,
maxsize: 100000000
})
];
...
// __mocks__/winston.ts
const winston = {
????
};
export default winston;
An error has surfaced: TypeError: Cannot read property 'File' of undefined