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

294
Views
En Jest, simule el constructor de una clase instanciada en la función probada

Quiero probar getSessionStorage() . Dentro getSessionStorage() estoy llamando a new RedisStore(process.env.REDIS_URL) . Esto arroja un error porque no se puede acceder a process.env.REDIS_URL fuera de un vpn.

¿Cómo puedo burlarme de RedisStore.constructor para evitar llamar a this.client.connect(); y así evitar el error?

RedisStore.js

 import { createClient } from "redis"; class RedisStore { /** * @param {string} url */ constructor(url) { this.client = createClient({ url }); this.client.on("error", (err) => console.log("Redis Client Error", err)); this.client.connect(); } async storeCallback(session) {} async loadCallback(id) {} async deleteCallback(id) {} } export default RedisStore;

getSessionStorage.js

 import RedisStore from "./RedisStore"; const getSessionStorage = ()=> { return new RedisStore(process.env.REDIS_URL); } export default getSessionStorage;

getSessionStorage.test.js

 import getSessionStorage from "./getSessionStorage.js"; describe("getSessionStorage", () => { it("should pass", () => { expect(getSessionStorage()).toMatchObject({ storeCallback: expect.any(Function), loadCallback: expect.any(Function), deleteCallback: expect.any(Function) }); }); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes burlarte de redis:

 jest.mock('redis', () => ({ createClient : jest.fn().mockReturnValue({ on: jest.fn(), connect: jest.fn() }), }));
about 4 years ago · Juan Pablo Isaza Report
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!