Say I have a class that's structured like this:
// Some class that calls super.get() and adds an additional param
export default class ClassB extends ClassA {
private foo: string;
constructor(params) {
super(params);
this.foo = 'bar';
}
public async get(params?: { [key: string]: any }): Promise<any> {
return super.get({
foo: this.foo,
...params,
});
}
}
I would like to test that super.get() was called with the provided parameters as well as the additional { foo: 'bar' }.
import ClassA from '../../src/ClassA';
import ClassB from '../../src/ClassB';
jest.mock('../../src/ClassA');
jest.unmock('../../src/ClassB');
describe('ClassB', () => {
describe('get', () => {
beforeAll(() => {
// I've tried mock implementation on classA here but didn't have much luck
// due to the extending not working as expected
});
it('should get with ClassA', async () => {
const classB = new ClassB();
const response = await classB.get({
bam: 'boozled',
});
// Check if classA fetch mock called with params?
});
});
});
How do I check that classA.fetch was actually called with the params I'm expecting?
Am I doing anything that's just completely wrong?
Thanks for any help!