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

875
Views
TypeError: moduleName.startsWith no es una función cuando se burla de "axios"

Estoy tratando de simular una función de obtención de axios pero obtengo TypeError: moduleName.startsWith is not a function cuando se burla de "axios". ¿Cuál sería la forma correcta de burlarse?

Error:

 FAIL src/tests/Sample.test.jsx ● Test suite failed to run TypeError: moduleName.startsWith is not a function 5 | import { backendUrl } from "../helper/constants" 6 | describe("test useEffect and axios", () => { > 7 | const mockGet = jest.mock(axios.get)

Muestra.prueba.jsx

 import { mount } from "enzyme" import { screen, render, act } from "@testing-library/react" import Sample from "../pages/Sample" import axios from "axios" import { backendUrl } from "../helper/constants" describe("test useEffect and axios", () => { const mockGet = jest.mock(axios.get) // THROWS ERROR HERE let wrapper it("should call axios", async () => { await act(async () => { mockGet.mockImplementationOnce(() => Promise.resolve({})) wrapper = mount(<Sample />) }) wrapper.update() await expect(mockGet).toHaveBeenCalledWith(backendUrl) }) })

Muestra.jsx

 import axios from "axios" import { useState, useEffect } from "react" import { backendUrl } from "../helper/constants" const Sample = () =>{ const [pets, setPets] = useState([]) useEffect(() => axios.get(backendUrl) .then(({data}) =>setPets(data.entries)) .catch((err)=>console.log(err)), []) return ( <> <p>I h8 all of you</p> {pets.map((e, i) =><h2 key={i}>{e.Link}</h2>)} </> ) } export default Sample
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que usar la sintaxis correcta como esta jest.mock('axios') así que en tu caso:

 jest.mock('axios') describe("test useEffect and axios", () => { const mockGet = jest.fn() let wrapper it("should call axios", async () => { await act(async () => { mockGet.mockImplementationOnce(() => Promise.resolve({})) wrapper = mount(<Sample />) }) wrapper.update() await expect(mockGet).toHaveBeenCalledWith(backendUrl) }) })
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!