Answer the question
In order to leave comments, you need to log in
How to mock an entire class in Jest and TS?
I write in Typescript and with the Jest framework.
There is a class that works with an instance of RedisClient, so I need to mock this instance.
I can't find the correct way to do this.
jest.mock('redis')
import {RedisClient} from 'redis'
import {RedisBroker} from '../src'
const mockedRedisClient = RedisClient as jest.MockedClass<typeof RedisClient>
describe('Testing of main module.', ()=>{
let client: RedisClient
let broker: RedisBroker
beforeEach(() => {
client = new mockedRedisClient({})
broker = new RedisBroker(client)
})
})
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (node_modules/redis/lib/individualCommands.js:24:13)
at Object.<anonymous> (node_modules/redis/index.js:1034:1)
Answer the question
In order to leave comments, you need to log in
as far as I remember, you can throw class mocks into the __mocks__ directory,
and es6 class mocks
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question