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

434
Views
React Testing Library fireEvent.mouseOver/mouseEnter no detecta css: cambios de desplazamiento

Tengo un botón que cambia de color y la escala de los niños al pasar el mouse. Cuando trato de desencadenar esta interacción con rtl/jest, mi prueba falla con el siguiente mensaje: Los Compared values have no visual difference.

Mi botón tiene el siguiente estilo:

 &:hover, &:focus { * { cursor: pointer; } background: ${(props) => lighten(0.1, props.theme.primary)}; // lighten function from polished transition: background 0.25s; figure { transform: scale(0.9); transition: transform 0.25s ease; } }

El JSX:

 <StyledFABButton aria-label="Open window" onClick={handleClickFAB}> <StyledIconWrapper data-testid="breifcase-icon-wrapper"> <BriefcaseIcon /> </StyledIconWrapper> </StyledFABButton>

Y mis pruebas:

 it("should change button appearance if FAB is hovered", () => { jest.useFakeTimers(); jest.spyOn(global, "setTimeout"); customRender(<FAB />, {}); const button = screen.getByLabelText(/Open window/i); fireEvent.mouseEnter(button); expect(button).not.toHaveStyle("background: #31c04d"); }); it("should change icon appearance if FAB is hovered", () => { jest.useFakeTimers(); jest.spyOn(global, "setTimeout"); customRender(<FAB />, {}); const button = screen.getByLabelText(/Open Recruitbot/i); fireEvent.mouseEnter(button); const iconWrapper = screen.getByTestId(/breifcase-icon-wrapper/i); expect(iconWrapper).toHaveStyle("transform: scale(0.9)"); });

He tenido problemas anteriores con funciones polished , pero esto no ha sido un problema desde que incorporé mi customRender , que simplemente envuelve el componente en ThemeProvider y ContextProvider .

EDITAR: Aquí está mi customRender:

 // contextProps is just a fake context object export const customRender = ( ui: any, { contextProps = baseMockContext, ...renderOptions }: any ) => { return render( <ThemeProvider theme={theme}> <AppContext.Provider value={contextProps}>{ui}</AppContext.Provider> </ThemeProvider>, renderOptions ); }; export * from "@testing-library/react";
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!