I am having issues when testing that the original method (from the base class), is called with some parameters, when testing an extended class. The class that I want to test is:
// ApiDataSource.js
import { RESTDataSource } from "apollo-datasource-rest";
export default class ApiDataSource extends RESTDataSource {
constructor() {
super();
this.baseURL = 'test';
}
//We add the authorization params to the get method
async get(path, params = {}, init = {}) {
return super.get(
path,
{
...params,
app_id: "test app id",
app_key: "test app key",
},
init
);
}
}
And basically, I would want to mock super.get()
to assert that when ApiDataSource.get()
is called, the super
method is called with the authorization parameters.
Something like:
// ApiDataSource.test.js
import ApiDataSource from './ApiDataSource'
// ...
test("adds the authorization parameters to the get call", async () => ({
const class = new ApiDataSource();
await class.get("test");
expect(mockedSuperGet).toHaveBeenCalledWith("test", {app_id: "test app id", app_key: "test app key"})
});
Any idea how to do that? have tried jest.mock()
jest.spyOn
and so on and I can't seem to get it...
CodeSandbox: https://codesandbox.io/s/example-test-api-data-source-6ldpk?file=/src/ApiDataSource.test.ts