Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda