Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
Event not changing the state of the label react-testing-library

Sorry i'm new to unit testing and i'm stuck on this.

I'm just testing the onClick of a "Show more" button.

Total size = 16 items, Page size = 15 items

so if I clicked the button, it should add 1 item to the currentResult

test('Show more button click works successfully', () => {
const state = {
search: {
  ...initialState.search,
  mainResult: SearchData.test.large,
  currentResult: SearchData.test.large.slice(0, 15),
  currentCount: 15,
  currentTotal: 16,
},
};

store = mockStore(state);
const { getByTestId } = render(
<Provider store={store}>
  <SearchListing {...props} />
 </Provider>
);
const showMoreBtn = getByTestId('search-listing-result-footer-btn');

expect(getByTestId('search-listing-result-footer-label')).toHaveTextContent('Showing 15 of 16 results');

userEvent.click(showMoreBtn);

expect(getByTestId('search-listing-result-footer-label')).toHaveTextContent('Showing 16 of 16 results');
});

Show more function, I'm chunking the mainResult so if I click the show more, I'll just add the next chunk to currentResult.

 const showMore = () => {
const newPageCount = pageCount + 1;
const newResult = [...currentResult, ...resultsChunk[newPageCount]];
dispatch(searchActions.showMore({ currentResult: newResult, currentCount: newResult.length }));
setPageCount(newPageCount);
};

Error message:

Expected element to have text content:
  Showing 16 of 16 results
Received:
  Showing 15 of 16 results

How can I update the mockStore after onClick? or is there any other way.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda