// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import { server } from './mocks/server';
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from './api/auth';
import { setLogger } from 'react-query';
import { mockedAccessToken, mockedRefreshToken } from './mocks/data';

beforeAll(() => {
  // Enable the mocking in tests.
  localStorage.setItem(ACCESS_TOKEN_KEY, mockedAccessToken);
  localStorage.setItem(REFRESH_TOKEN_KEY, mockedRefreshToken);
  server.listen();
});

afterEach(() => {
  // Reset any runtime handlers tests may use.
  server.resetHandlers();
});

afterAll(() => {
  // Clean up once the tests are done.
  localStorage.clear();
  server.close();
});

// silence react-query errors
setLogger({
  log: console.log,
  warn: console.warn,
  error: () => {}
});
