'Second identical jest test failing after the first one passes
I have two identical jest tests, the first one passes and the second fails. From what I have read it could be something to do with mocking the someFunction. I am clearing all the mocks before each test, I have tried jest.resetAllMocks(); but that does not seem to work.
const authenticatedUser = {
"id": 1,
"accessFlags": [],
}
jest.mock("../src/someFunction", () => ({
return {someData: ["a", "b"]}
}));
describe("My Tests", () => {
let ex;
beforeEach(() => {
jest.clearAllMocks();
ex = new FauxExpress();
});
it("Description", async () => {
const req = {
user: { ...authenticatedUser, access: ["admin"] },
};
await doSomethingUsingMockedSomeFunction(req, ex.res);
expect(ex.res.statusCode).toBe(200);
});
it("Description", async () => {
const req = {
user: { ...authenticatedUser, access: ["admin"] },
};
await doSomethingUsingMockedSomeFunction(req, ex.res);
expect(ex.res.statusCode).toBe(200);
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
