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

311
Views
Jest.js: Simular el valor de retorno de URLSearchParams a nulo no logra insertar la prueba en una ruta de prueba falsa
jest.spyOn( URLSearchParams.prototype, 'get' ).mockReturnValue( null )

Espero que este código provoque get la evaluación sea null , pero este no parece ser el caso, se está utilizando Istanbul y el código a continuación nunca evalúa la condición falsa (que se muestra como una falla en cubrir ?? '' :

 const startDate: string = new URLSearchParams( queryParams ).get( 'start' ) ?? '' const endDate: string = new URLSearchParams( queryParams ).get( 'end' ) ?? ''

¿Alguna idea de cuál podría ser el problema?

Para el contexto, aquí está el comienzo del componente y la prueba relevantes:

 // component under test: const EmployeeTable = () => { const queryParams = useLocation().search const { id } = useParams<{ id: string }>() const employeeId: number = Number( id ) const startDate: string = new URLSearchParams( queryParams ).get( 'start' ) ?? '' const endDate: string = new URLSearchParams( queryParams ).get( 'end' ) ?? '' // the jest test it( 'should render the employee table page section without data', () => { jest.spyOn( dataHooks, 'useEmployeeTimeSummaries' ).mockImplementation( (): any => ( { data: null, } ) ) jest.spyOn( URLSearchParams.prototype, 'get' ).mockReturnValue( null ) const { getByTestId } = render( <EmployeeTable />, { wrapper: reactQueryProvider } ) expect( getByTestId( TEST_ID_EMPLOYEE_TABLE ) ).toBeInTheDocument() } )
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!