Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade for mock date #198

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ScheduleTimeModalProps } from './index.type';
import { renderWithTheme } from '../../../../testUtils/customRender';
import { act, cleanup, fireEvent, screen } from '@testing-library/react';
import MockDate from 'mockdate';
import dayjs from 'dayjs';
import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery';

describe('sqle/Order/AuditDetail/ScheduleTimeModal', () => {
Expand All @@ -24,7 +23,6 @@ describe('sqle/Order/AuditDetail/ScheduleTimeModal', () => {
};

beforeEach(() => {
MockDate.set(dayjs('2023-12-18 12:00:00').valueOf());
jest.useFakeTimers();
// date picker : custom attr [hideSuperIcon]
jest.spyOn(console, 'error').mockImplementation(() => {});
Expand All @@ -33,7 +31,6 @@ describe('sqle/Order/AuditDetail/ScheduleTimeModal', () => {
afterEach(() => {
jest.useRealTimers();
jest.clearAllMocks();
MockDate.reset();
(console.error as jest.Mock).mockRestore();
cleanup();
});
Expand Down Expand Up @@ -98,6 +95,7 @@ describe('sqle/Order/AuditDetail/ScheduleTimeModal', () => {
});

it('render submit btn', async () => {
MockDate.set(new Date('2024-12-18T00:00:00Z').getTime());
submitFn.mockImplementation(() => new Promise(() => 1));
const { baseElement } = customRender({
open: true
Expand All @@ -120,6 +118,7 @@ describe('sqle/Order/AuditDetail/ScheduleTimeModal', () => {
fireEvent.click(submitBtn);
await act(async () => jest.advanceTimersByTime(300));
expect(submitFn).toBeCalled();
expect(submitFn).toBeCalledWith('2024-01-29T00:00:00+08:00');
expect(submitFn).toBeCalledWith('2024-12-29T00:00:00+08:00');
MockDate.reset();
});
});
Loading