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));
});