Open
Description
I have a module, let's call it myModule that imports @myScope/myPackage
myPackage contains two functions - foo and goo
myModule exports the class 'MyClass' that uses both package functions
when I test MyClass I would like to mock the myPackage with mockDeep of jest-mock-extended
in each test, I would like to mock different return value or implementations of foo and goo
I didn't find a way to do so
// myModule.ts
import { foo, goo } from '@myScope/myPackage'
export class MyClass {
toTest(): string {
const a = foo().moo().koo() // that is why I want deepMock
return goo(a + 'test')
}
}
// myModule.test.ts
import { foo, goo } from '@myScope/myPackage'
import { MyClass } from './myModule'
describe('', () => {
let myClass: MyClass
beforeEach(() => {
myClass = new MyClass()
})
it('should return an empty string', async () => {
goo.mockReturnValue('')
const result = myClass.toTest()
expect(result).toEqual('')
})
})
Metadata
Assignees
Labels
No labels
Activity