2023-03-10 14:12:49 +08:00
|
|
|
import React from 'react';
|
|
|
|
import message, { actWrapper } from '..';
|
|
|
|
import { act, render, waitFakeTimer } from '../../../tests/utils';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
import { awaitPromise, triggerMotionEnd } from './util';
|
|
|
|
|
|
|
|
describe('message static warning', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
actWrapper(act);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
2023-03-10 14:12:49 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
// Clean up
|
|
|
|
message.destroy();
|
|
|
|
await triggerMotionEnd();
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useRealTimers();
|
2023-03-10 14:12:49 +08:00
|
|
|
|
|
|
|
await awaitPromise();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Follow test need keep order
|
|
|
|
it('no warning', async () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-03-10 14:12:49 +08:00
|
|
|
|
|
|
|
message.success({
|
|
|
|
content: <div className="bamboo" />,
|
|
|
|
duration: 0,
|
|
|
|
});
|
|
|
|
await waitFakeTimer();
|
|
|
|
|
|
|
|
expect(document.querySelector('.bamboo')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(errSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('warning if use theme', async () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-03-10 14:12:49 +08:00
|
|
|
render(<ConfigProvider theme={{}} />);
|
|
|
|
|
|
|
|
message.success({
|
|
|
|
content: <div className="light" />,
|
|
|
|
duration: 0,
|
|
|
|
});
|
|
|
|
await waitFakeTimer();
|
|
|
|
|
|
|
|
expect(document.querySelector('.light')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
"Warning: [antd: message] Static function can not consume context like dynamic theme. Please use 'App' component instead.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|