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

196
Views
la función simulada de broma no funciona en mi caso de prueba

cuando importo módulos, me burlo de ellos con jest.mock() api:

 import analytics, { fakeAnalyticsApi } from "../../middleware/analytics"; jest.mock("../../middleware/analytics", () => { const orginalModules = jest.requireActual("../../middleware/analytics"); return { __esModule: true, ...orginalModules, fakeAnalyticsApi: jest.fn(() => Promise.resolve("success")), }; });

luego, cuando llamo a la función "fakeAnalyticsApi", se ejecuta su versión original.

archivo de prueba completo:

 import analytics, { fakeAnalyticsApi } from "../../middleware/analytics"; jest.mock("../../middleware/analytics", () => { const orginalModules = jest.requireActual("../../middleware/analytics"); return { __esModule: true, ...orginalModules, fakeAnalyticsApi: jest.fn(() => Promise.resolve("success")), }; }); const create = () => { const store = { getState: jest.fn(() => {}), dispatch: jest.fn(), }; const next = jest.fn(); const invoke = (action) => analytics(store)(next)(action); return { store, next, invoke }; }; // suite test describe("analytics middleware", () => { test("should pass on irrelevant keys", () => { const { next, invoke } = create(); const action = { type: "IRREVELANT" }; invoke(action); expect(next).toHaveBeenCalledWith(action); expect(fakeAnalyticsApi).not.toHaveBeenCalled(); }); test("should make an analytics API call", () => { const { next, invoke } = create(); const action = { type: "REVELANT", meta: { analytics: { event: "REVELANT", data: { extra: "stuff" }, }, }, }; invoke(action); expect(fakeAnalyticsApi).toHaveBeenCalled(); expect(next).toHaveBeenCalledWith(action); }); });

y me sale el siguiente error:

 ● analytics middleware › should make an analytics API call expect(jest.fn()).toHaveBeenCalled() Expected number of calls: >= 1 Received number of calls: 0 39 | }; 40 | invoke(action); > 41 | expect(fakeAnalyticsApi).toHaveBeenCalled(); | ^ 42 | expect(next).toHaveBeenCalledWith(action); 43 | }); 44 | });

Registro una declaración en la función de versión original de "fakeAnalyticsApi", parece que se llamó a la versión original porque la consola registra la declaración

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!