I'm writing some jest tests to test an async method. If I run each test individually, it works! However, when I run the whole suite, they fail. The mock values from one test end up in another test because I suspect that jest is not waiting for one to finish before moving onto another.
describe('testing method', () => {
test('test case 1', async () => {
dependentService.method.mockResolvedValueOnce(mockResult1);
expect(await testSubject(input)).toBe(expectedResult);
});
test('test case 2', async () => {
dependentService.method.mockResolvedValueOnce(mockResult2);
expect(await testSubject(input)).toBe(expectedResult);
});
});
In the above sample code snippet, the mockResult2 is used in the test case 1, instead of mockResult1. How do I get this to behave as I expect?