Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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);
  });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!