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

313
Views
cómo simular firebase .auth().currentUser en .test.js

Quiero probar la siguiente función.

 export async function getIdToken() { const currentUser = firebase.auth().currentUser; if (currentUser) { return currentUser.getIdToken(); } else { return undefined; } } export async function getSomethingViaHTTPS() { const idToken = await getIdToken(); const response = await fetch("https://someURL.com", { method: "GET", headers: { Authorization: "Bearer " + idToken } }); if (response.status === 200) { return await response.json(); } throw new Error("failed to fetch data breaches: " + response.status + ": " + (await response.text())); }

Ahora no sé cómo puedo probarlo ya que durante la prueba el usuario actual no estaría definido. ¿Hay alguna manera de burlarse del usuario actual? Esta es mi función de prueba:

 describe("something via https", () => { const mockGetSomethingAPI = responseBody => { fetchMock.once(req => { if (req.url !== "https://someURL.com") { return Promise.reject({}); } return Promise.resolve(JSON.stringify(responseBody)); }); }; it("get something", async () => { mockGetSomethingAPI({ "something": "some text" }); expect(await mockGetSomethingAPI()).toEqual({ something: "testestest" }); }); });
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!