[Unit testing] Vitest, mock Time

import { afterEach, test, expect, vi, beforeEach } from 'vitest';
import { render } from 'test/utilities';
import TimeZone from '.';

beforeEach(() => {
  // freeze time
  vi.useFakeTimers();
  // set system time to a certain point
  vi.setSystemTime(1679492355195);
});

test('it should render successfully', () => {
  render(<TimeZone />);
});

test('should match the snapshot', async () => {
  const { container } = render(<TimeZone />);
  expect(container).toMatchSnapshot();
});

afterEach(() => {
  vi.useRealTimers();
});

 

posted @ 2023-09-27 21:39  Zhentiw  阅读(39)  评论(0编辑  收藏  举报