Imagine having a class structure like this:
located at ./src/myClass.ts
class myClass{
methodA(){
...
}
methodB(){
...
}
}
Now, let's say I need to mock method A. To do this, I created a file
./src/mocks/myClass.ts
class myClass{
methodA(){
...
}
}
After that, in ./tests/myClass.test.ts
'use strict';
import { myClass } from "../src/myClass";
jest.mock('../src/myClass');
describe('myClass', () => {
it('returns methodB', () => {
const c = new myClass();
//methodA is correctly mocked here
c.methodA();
// how do I make jest use the original method here?
const data= c.methodB();
expect(data)
.toMatchObject({})
},
3000)
});
As stated in the comments above, I am struggling to access the original methodB.
My assumption is that I am mocking the entire class instead of mocking individual methods within the class. What is the best practice in jest to create a mock file that only mocks specific class methods?