I want to test an action. Inside that service action, I am calling another service action. code looks like below
describe("Test auth service", () => {
describe("action", ()=>{
let broker = new ServiceBroker({
logger: false,
});
let authService = broker.createService(TestAuthService);
let storageService = broker.createService(TestStorageService);
beforeAll(() => broker.start());
afterAll(() => broker.stop());
for (
let i = 0;
i < params.length;
i++
) {
const {
testName,
input,
expectedResponse,
} = params[i];
describe("unit test", () => {
afterAll(() => {
//Tear down
});
storageService.actions.uploadPhotoToStorage = jest.fn(()=> Prmoise.resolve("Uploaded"))
test(testName, async () => {
const userData = await dummyUserSignup(apiService, authService);
const uploadVideoResponse = await broker.call("auth.uploadPhoto", {...input, user: userData});
//assert
});
});
}
})
});
There is a uploadPhoto
action present in auth
service. From uploadPhoto
action I am calling uploadPhotoToStorage
in storage service.
I wanted to mock the uploadPhotoToStorage
in storage service.
Is there any way I can mock action after creating the service.