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

213
Views
¿Cómo establecer el valor de la variable de un componente funcional React para la prueba Cypress?

Hay un componente funcional de React que quiero cubrir con las pruebas de Cypress:

 import { ReactElement, useEffect, VFC } from 'react'; import { finalize, Subscription } from 'rxjs'; import { WebAdminUserAccountManagementService } from '@stxr/admin_codecs'; import { setAllUsers, useAllUsers } from '@/gateway/users'; const AllUsers: VFC = (): ReactElement => { const { data, loading, error } = useAllUsers(); const loadUsers = useCallback(() => { setAllUsers({ loading: true, }); const users: UserAccount[] = []; subscription = WebAdminUserAccountManagementService.getAllUserAccounts() .pipe(finalize(() => subscription?.unsubscribe())) .subscribe({ next: (account) => users.push(account), complete: () => { setAllUsers({ data: users, loading: false, }); }, error: (e) => { if (e === 'ErrorNotification/permissionDenied') return setAllUsers({ loading: false, error: e, }); return setAllUsers({ loading: false, error: `Error loading users${e ? `: (${e})` : '.'}`, }); }, }); }, []); useEffect(() => { loadUsers(); }, [loadUsers]); if (loading || !data) return <Loading centered data-testid="loader" />; return <div data-testid="main-container">Hell yeeeeeaaah!<div/> }; export default AllUsers;

y así es como estoy tratando de cubrir este componente con pruebas:

 import { mount } from 'cypress/react'; import AllUsers from '@/pages/users/all'; import { setAllUsers } from '@/gateway/users'; describe('<AllUsers />', () => { it('should show loader if there is no data', () => { mount(<AllUsers />); cy.get('[data-testid="loader"]').should('be.visible'); }); it('should have main container if data exists', () => { setAllUsers({ loading: false, data: [] }); mount(<AllUsers />); cy.get('[data-testid="main-container"]').should('be.visible'); }); });

El primer escenario, donde data no están undefined y loading es true , se pasa con éxito. El segundo, donde necesito que data sean una matriz, no se pasa. ¿Cómo puedo simular data y loading para las pruebas de Cypress?

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!