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

106
Vistas
React jest appropriate place to use beforeEach

So I am trying to setup my JEST test and want to set some local storage state before running all the tests. I have used it under server.js. Is that a good place to set, so that all tests are able to access the local storage mocked value?

//src/setupTests.js
import '@testing-library/jest-dom/extend-expect';
import {server} from './mocks/server';

beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())

Below is my server.js

import {setupServer} from "msw/node";
import {handlers} from './handlers'
import mockData from "./data/mockData";

// This configures a request mocking server with the given request handlers.
export const server = setupServer(...handlers);

beforeEach(() => {
    localStorage.setItem('mockData', JSON.stringify(mockData));
});
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