I am using jest to do unit testing. I have a Login screen that calls a login function that is in a service. I can mock the login function using
jest.spyOn(AuthenticationService, 'login').mockImplementation(async (username, password) => { console.log('mock login called', username, password); return Promise.resolve(true)});
and that intercepts the login function and works as intended. The problem is that I actually want to intercept the authenticate inside the same service as login function that login calls. when I change 'login' to 'authenticate' it does nothing. all the functions just get triggered as normal and nothing is mocked
I have also tried mocking with the following with no luck
jest.mock('../../auth/authentication.service', () => ({
...jest.requireActual('../../auth/authentication.service'),
authenticate: jest.fn((username, password) => {
console.log('mock login called', username, password);
//return Promise.resolve(true);
})
}));
I have a feeling it is to do with the fact the login page is calling login but is never actually calling authenticate from itself but not sure if that makes a difference.
authenticate and login are both exported correctly from the service so both should be available to mock