chore: migrate to vitest (#42506)

* chore: migrate to vitest

* chore: update ci

* fix: test correctly

* test: support puppeteer

* chore: update coverage

* chore: update include/exclude

* chore: update config

* test: update incorrect tests

* chore: update script

* chore: update

* fix: should close browser at the ended

* chore: improve

* fix: test cause tsc error

* fix: eslint error

* chore: exclude correctly

* test: update snap and fix some tests

* chore: update test config

* fix: countup.js

* fix: incorrect test

* chore: update reference

* test: update

* fix: countup.js

* fix: timeout

* chore: update site test

* fix: fixed countup version

* chore: remove unsed code

* test: update

* test: update demo timeout

* test: update timeout

* chore: update image test

* chore: update threads

* fix: image/svg+xml test failed

* chore: limits threads

* test: update test coverage include

* chore: remove jest files

* chore: rename jest to vi

* chore: update document

* chore: fix missing @types/jsdom

* chore: update coverage

* chore: update snap

* fix:watermark test cases are incorrect

* feat: update ignore comment

* test: fix test case

* test: reset body scrollTop

* test: clean up

* test: use vi

* test: update snapshot

* test: update snapshot

* test: fix dropdown test failed

* fix: toHaveStyle cause test fail

* test: improve test case

* test: fix

* fix: color failed, refer to https://github.com/jsdom/jsdom/pull/3560

* test: fix

* test: fix

* test: fix circular import

* test: revert

* ci: coverage failed

* test: fix c8 ignore comment

* chore: incorrect config

* chore: fix ignore ci

* test: revert svg+xml

* test: fix realTimers

* feat: rc-trigger should be remove

* test: fix some failed test

* chore: remove unused deps and configure eslint-plugin-vitest

* test: update snap

* chore: remove jest

* test: fix lint error

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
Dunqing 2023-06-07 11:54:50 +08:00 committed by GitHub
parent 9b22fd4258
commit 6759887c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
454 changed files with 3575 additions and 3664 deletions

View File

@ -21,4 +21,3 @@ coverage
**/*.d.ts
# Scripts
scripts/previewEditor/**/*
jest-stare

View File

@ -3,7 +3,7 @@ module.exports = {
'airbnb',
'prettier',
'plugin:compat/recommended',
'plugin:jest/recommended',
'plugin:vitest/recommended',
'plugin:react/recommended',
'plugin:import/typescript',
'plugin:markdown/recommended',
@ -12,7 +12,6 @@ module.exports = {
browser: true,
node: true,
jasmine: true,
jest: true,
es6: true,
},
settings: {
@ -25,7 +24,15 @@ module.exports = {
},
},
parser: '@typescript-eslint/parser',
plugins: ['react', '@babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'],
plugins: [
'react',
'@babel',
'vitest',
'@typescript-eslint',
'react-hooks',
'unicorn',
'markdown',
],
// https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034
overrides: [
{
@ -152,8 +159,10 @@ module.exports = {
'scripts/**',
'**/*.test.js',
'**/__tests__/*',
'__mocks__/**',
'*.config.js',
'**/*.md',
'vitest*config.ts',
],
},
],
@ -179,12 +188,12 @@ module.exports = {
'no-restricted-globals': 0,
'max-classes-per-file': 0,
'jest/no-test-callback': 0,
'jest/expect-expect': 0,
'jest/no-done-callback': 0,
'jest/valid-title': 0,
'jest/no-conditional-expect': 0,
'jest/no-standalone-expect': 0,
'vitest/prefer-to-be': 0,
'vitest/expect-expect': 0,
'vitest/no-done-callback': 0,
'vitest/valid-title': 0,
'vitest/no-conditional-expect': 0,
'vitest/no-standalone-expect': 0,
'unicorn/better-regex': 2,
'unicorn/prefer-string-trim-start-end': 2,

View File

@ -191,7 +191,7 @@ jobs:
# dom test
- name: dom test
if: ${{ matrix.module == 'dom' }}
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
run: npm test -- --shard=${{matrix.shard}} --coverage
- name: persist coverages
if: ${{ matrix.module == 'dom' && matrix.react == '17' }}
@ -347,7 +347,7 @@ jobs:
- name: test
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}}
run: npm test -- --shard=${{matrix.shard}}
env:
LIB_DIR: ${{ matrix.module }}
needs: compile

1
.gitignore vendored
View File

@ -58,7 +58,6 @@ components/version/token-meta.json
# Image snapshot diff
__diff_output__/
__image_snapshots__/
/jest-stare
/imageSnapshots
/imageDiffSnapshots

View File

@ -1,23 +0,0 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');
// jest config for image snapshots
module.exports = {
setupFiles: ['./tests/setup.js'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'image\\.test\\.(j|t)s$',
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
},
},
preset: 'jest-puppeteer',
testTimeout: 10000,
};

View File

@ -1,68 +0,0 @@
const compileModules = ['react-sticky-box', 'rc-tween-one', '@babel', '@ant-design', 'countup.js'];
const ignoreList = [];
// cnpm use `_` as prefix
['', '_'].forEach((prefix) => {
compileModules.forEach((module) => {
ignoreList.push(`${prefix}${module}`);
});
});
const transformIgnorePatterns = [
// Ignore modules without es dir.
// Update: @babel/runtime should also be transformed
`/node_modules/(?!${ignoreList.join('|')})[^/]+?/(?!(es)/)`,
];
function getTestRegex(libDir) {
if (['dist', 'lib', 'es'].includes(libDir)) {
return 'demo\\.test\\.(j|t)sx?$';
}
return '.*\\.test\\.(j|t)sx?$';
}
module.exports = {
verbose: true,
testEnvironment: 'jsdom',
setupFiles: ['./tests/setup.js', 'jest-canvas-mock'],
setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'md'],
modulePathIgnorePatterns: ['/_site/'],
moduleNameMapper: {
'/\\.(css|less)$/': 'identity-obj-proxy',
'^antd$': '<rootDir>/components/index',
'^antd/es/(.*)$': '<rootDir>/components/$1',
},
testPathIgnorePatterns: ['/node_modules/', 'dekko', 'node', 'image.test.js', 'image.test.ts'],
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.(m?)js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: getTestRegex(process.env.LIB_DIR),
collectCoverageFrom: [
'components/**/*.{ts,tsx}',
'!components/*/style/index.tsx',
'!components/style/index.tsx',
'!components/*/locale/index.tsx',
'!components/*/__tests__/type.test.tsx',
'!components/**/*/interface.{ts,tsx}',
'!components/*/__tests__/image.test.{ts,tsx}',
'!components/__tests__/node.test.tsx',
'!components/*/demo/*.tsx',
'!components/*/design/**',
],
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfig: './tsconfig.test.json',
},
},
testEnvironmentOptions: {
url: 'http://localhost',
},
// bail: true,
maxWorkers: '50%',
};

View File

@ -1,19 +0,0 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');
// jest config for server render environment
module.exports = {
setupFiles: ['./tests/setup.js'],
setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'node\\.test\\.(j|t)sx$',
testEnvironment: 'node',
transformIgnorePatterns,
// bail: true,
};

View File

@ -1,21 +0,0 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');
// jest config for server render environment
module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'check-site\\.(j|t)s$',
testEnvironment: 'node',
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
},
},
};

View File

@ -1,16 +1,17 @@
import type { TriggerProps } from '@rc-component/trigger';
import MockTrigger from '@rc-component/trigger/lib/mock';
import MockTrigger from '@rc-component/trigger/es/mock';
import * as React from 'react';
import { TriggerMockContext } from '../../shared/demoTestContext';
import { TriggerMockContext } from '../../tests/shared/demoTestContext';
let OriginTrigger = jest.requireActual('@rc-component/trigger');
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
const { default: OriginTrigger } = await vi.importActual<typeof import('@rc-component/trigger')>(
'@rc-component/trigger',
);
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
const context = React.useContext(TriggerMockContext);
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
(global as any).triggerProps = props;
globalThis.triggerProps = props;
const mergedProps = {
...props,

View File

@ -1,8 +1,8 @@
import React from 'react';
import { TriggerMockContext } from '../../../shared/demoTestContext';
import { TriggerMockContext } from '../../../tests/shared/demoTestContext';
const { default: OriginPortal } = await vi.importActual<typeof import('rc-util/es/Portal')>('rc-util/es/Portal');
let OriginPortal = jest.requireActual('rc-util/lib/Portal');
OriginPortal = OriginPortal.default ?? OriginPortal;
class MockPortal extends React.Component<{ children?: React.ReactNode }> {
container: boolean;

View File

@ -0,0 +1,3 @@
import Mock from 'rc-virtual-list/es/mock';
export default Mock;

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`antd exports modules correctly 1`] = `
exports[`antd > exports modules correctly 1`] = `
[
"Affix",
"Alert",
@ -37,7 +37,9 @@ exports[`antd exports modules correctly 1`] = `
"List",
"Mentions",
"Menu",
"message",
"Modal",
"notification",
"Pagination",
"Popconfirm",
"Popover",
@ -59,6 +61,7 @@ exports[`antd exports modules correctly 1`] = `
"Table",
"Tabs",
"Tag",
"theme",
"TimePicker",
"Timeline",
"Tooltip",
@ -68,10 +71,7 @@ exports[`antd exports modules correctly 1`] = `
"TreeSelect",
"Typography",
"Upload",
"Watermark",
"message",
"notification",
"theme",
"version",
"Watermark",
]
`;

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`SetUp.Test diff of React 18 & React 17 1`] = `
exports[`SetUp.Test > diff of React 18 & React 17 1`] = `
NodeList [
<div>
bamboo

View File

@ -1,6 +1,7 @@
import * as antd from '..';
const OLD_NODE_ENV = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
const antd = require('..');
describe('antd', () => {
afterAll(() => {

View File

@ -3,21 +3,24 @@ import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';
(global as any).testConfig = {};
globalThis.testConfig = {};
jest.mock('../../tests/shared/demoTest', () => {
vi.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
(global as any).testConfig[name] = option;
globalThis.testConfig[name] = option;
}
fakeDemoTest.rootPropsTest = () => {};
return fakeDemoTest;
return {
default: fakeDemoTest,
rootPropsTest: () => {},
};
});
describe('node', () => {
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
vi.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});
// Find the component exist demo test file
@ -27,23 +30,27 @@ describe('node', () => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];
// Test for ssr
describe(componentName, () => {
// eslint-disable-next-line vitest/valid-describe-callback
describe(componentName, async () => {
const demoList = globSync(`./components/${componentName}/demo/*.tsx`);
// Use mock to get config
require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require
const option = (global as any).testConfig?.[componentName];
await import(`../../${componentTestFile}`);
demoList.forEach((demoFile) => {
const option = globalThis.testConfig?.[componentName];
const skip: string[] = option?.skip || [];
const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it;
test(demoFile, () => {
const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require
test(
demoFile,
async () => {
const Demo = (await import(`../../${demoFile}`)).default;
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
});
},
15000,
);
});
});
});

View File

@ -7,7 +7,7 @@ export interface BaseProps {
style?: React.CSSProperties;
}
/* istanbul ignore next */
/* c8 ignore start */
export default function genPurePanel<ComponentProps extends BaseProps>(
Component: any,
defaultPrefixCls?: string,
@ -96,3 +96,4 @@ export default function genPurePanel<ComponentProps extends BaseProps>(
);
} as typeof Component;
}
/* c8 ignore stop */

View File

@ -7,7 +7,7 @@ describe('getScroll', () => {
});
it('getScroll window', async () => {
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
window.pageXOffset = x;
window.pageYOffset = y;
});
@ -18,7 +18,7 @@ describe('getScroll', () => {
});
it('getScroll document', async () => {
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
document.documentElement.scrollLeft = x;
document.documentElement.scrollTop = y;
});
@ -30,7 +30,7 @@ describe('getScroll', () => {
it('getScroll div', async () => {
const div = document.createElement('div');
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
div.scrollLeft = x;
div.scrollTop = y;
});
@ -42,7 +42,7 @@ describe('getScroll', () => {
it('getScroll documentElement', async () => {
const div: any = {};
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
div.scrollLeft = null;
div.scrollTop = null;
div.documentElement = {};

View File

@ -11,7 +11,7 @@ describe('Test ResponsiveObserve', () => {
return null;
};
render(<Demo />);
const subscribeFunc = jest.fn();
const subscribeFunc = vi.fn();
const token = responsiveObserveRef.subscribe(subscribeFunc);
expect(
responsiveObserveRef.matchHandlers[responsiveObserveRef.responsiveMap.xs].mql.matches,

View File

@ -2,10 +2,10 @@ import { waitFakeTimer } from '../../../tests/utils';
import scrollTo from '../scrollTo';
describe('Test ScrollTo function', () => {
const dateNowMock = jest.spyOn(Date, 'now');
const dateNowMock = vi.spyOn(Date, 'now');
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
beforeEach(() => {
@ -13,16 +13,16 @@ describe('Test ScrollTo function', () => {
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
afterEach(() => {
jest.clearAllTimers();
vi.clearAllTimers();
dateNowMock.mockClear();
});
it('test scrollTo', async () => {
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
window.scrollY = y;
window.pageYOffset = y;
});
@ -36,7 +36,7 @@ describe('Test ScrollTo function', () => {
});
it('test callback - option', async () => {
const cbMock = jest.fn();
const cbMock = vi.fn();
scrollTo(1000, {
callback: cbMock,
});

View File

@ -9,19 +9,19 @@ import TransButton from '../transButton';
describe('Test utils function', () => {
describe('throttle', () => {
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
afterEach(() => {
jest.clearAllTimers();
vi.clearAllTimers();
});
it('throttle function should work', async () => {
const callback = jest.fn();
const callback = vi.fn();
const throttled = throttleByAnimationFrame(callback);
expect(callback).not.toHaveBeenCalled();
@ -34,7 +34,7 @@ describe('Test utils function', () => {
});
it('throttle function should be canceled', async () => {
const callback = jest.fn();
const callback = vi.fn();
const throttled = throttleByAnimationFrame(callback);
throttled();
@ -54,7 +54,7 @@ describe('Test utils function', () => {
});
it('should trigger onClick when press enter', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(<TransButton onClick={onClick}>TransButton</TransButton>);
@ -75,7 +75,7 @@ describe('Test utils function', () => {
});
it('isStyleSupport return false in service side', () => {
const spy = jest
const spy = vi
.spyOn(window.document, 'documentElement', 'get')
.mockImplementation(() => undefined as unknown as HTMLElement);
expect(isStyleSupport('color')).toBe(false);

View File

@ -1,8 +1,10 @@
import type { SpyInstance } from 'vitest';
describe('Test warning', () => {
let spy: jest.SpyInstance;
let spy: SpyInstance;
beforeAll(() => {
spy = jest.spyOn(console, 'error').mockImplementation(() => {});
spy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
@ -10,7 +12,7 @@ describe('Test warning', () => {
});
beforeEach(() => {
jest.resetModules();
vi.resetModules();
});
afterEach(() => {

View File

@ -1,13 +1,15 @@
import React from 'react';
import mountTest from '../../../tests/shared/mountTest';
import { render, fireEvent, getByText, waitFakeTimer, act } from '../../../tests/utils';
import { act, fireEvent, getByText, render, waitFakeTimer } from '../../../tests/utils';
import Wave from '../wave';
(global as any).isVisible = true;
let isVisible = vi.hoisted(() => true);
jest.mock('rc-util/lib/Dom/isVisible', () => {
const mockFn = () => (global as any).isVisible;
return mockFn;
vi.mock('rc-util/es/Dom/isVisible', () => {
const mockFn = () => isVisible;
return {
default: mockFn,
};
});
describe('Wave component', () => {
@ -29,44 +31,37 @@ describe('Wave component', () => {
}
(window as any).ResizeObserver = FakeResizeObserver;
jest.useFakeTimers();
vi.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
expect(obCnt).not.toBe(0);
expect(disCnt).not.toBe(0);
});
beforeEach(() => {
(global as any).isVisible = true;
isVisible = true;
document.body.innerHTML = '';
});
afterEach(() => {
jest.clearAllTimers();
afterEach(async () => {
await vi.runAllTimersAsync();
vi.clearAllTimers();
const styles = document.getElementsByTagName('style');
for (let i = 0; i < styles.length; i += 1) {
styles[i].remove();
}
});
function getWaveStyle() {
const styleObj: Record<string, string> = {};
function getWaveColor() {
const { style } = document.querySelector<HTMLElement>('.ant-wave')!;
style.cssText.split(';').forEach((kv) => {
if (kv.trim()) {
const cells = kv.split(':');
styleObj[cells[0].trim()] = cells[1].trim();
}
});
return styleObj;
return style.getPropertyValue('--wave-color');
}
function waitRaf() {
act(() => {
jest.advanceTimersByTime(100);
vi.advanceTimersByTime(100);
});
}
@ -90,7 +85,7 @@ describe('Wave component', () => {
});
it('invisible in screen', () => {
(global as any).isVisible = false;
isVisible = false;
const { container, unmount } = render(
<Wave>
<button type="button">button</button>
@ -119,9 +114,7 @@ describe('Wave component', () => {
fireEvent.click(container.querySelector('button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toBeFalsy();
expect(getWaveColor()).toBeFalsy();
unmount();
});
@ -129,7 +122,7 @@ describe('Wave component', () => {
it('wave color is not grey', () => {
const { container, unmount } = render(
<Wave>
<button type="button" style={{ borderColor: 'red' }}>
<button type="button" style={{ borderColor: 'rgb(255, 0, 0)' }}>
button
</button>
</Wave>,
@ -138,8 +131,7 @@ describe('Wave component', () => {
fireEvent.click(container.querySelector('button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('red');
expect(getWaveColor()).toEqual('rgb(255, 0, 0)');
unmount();
});
@ -147,15 +139,14 @@ describe('Wave component', () => {
it('read wave color from border-top-color', () => {
const { container, unmount } = render(
<Wave>
<div style={{ borderTopColor: 'blue' }}>button</div>
<div style={{ borderTopColor: 'rgb(0, 0, 255)' }}>button</div>
</Wave>,
);
fireEvent.click(getByText(container, 'button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('blue');
expect(getWaveColor()).toEqual('rgb(0, 0, 255)');
unmount();
});
@ -163,15 +154,14 @@ describe('Wave component', () => {
it('read wave color from background color', () => {
const { container, unmount } = render(
<Wave>
<div style={{ backgroundColor: 'green' }}>button</div>
<div style={{ backgroundColor: 'rgb(0, 128, 0)' }}>button</div>
</Wave>,
);
fireEvent.click(getByText(container, 'button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('green');
expect(getWaveColor()).toEqual('rgb(0, 128, 0)');
unmount();
});
@ -179,15 +169,14 @@ describe('Wave component', () => {
it('read wave color from border firstly', () => {
const { container, unmount } = render(
<Wave>
<div style={{ borderColor: 'yellow', backgroundColor: 'green' }}>button</div>
<div style={{ borderColor: 'rgb(255, 0, 0)', backgroundColor: 'green' }}>button</div>
</Wave>,
);
fireEvent.click(getByText(container, 'button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('yellow');
expect(getWaveColor()).toEqual('rgb(255, 0, 0)');
unmount();
});
@ -222,7 +211,7 @@ describe('Wave component', () => {
});
it('not show when hidden', () => {
(global as any).isVisible = false;
isVisible = false;
const { container } = render(
<Wave>
@ -271,7 +260,7 @@ describe('Wave component', () => {
it('wave color should inferred if border is transparent and background is not', () => {
const { container, unmount } = render(
<Wave>
<button type="button" style={{ borderColor: 'transparent', background: 'red' }}>
<button type="button" style={{ borderColor: 'transparent', background: 'rgb(255, 0, 0)' }}>
button
</button>
</Wave>,
@ -279,8 +268,7 @@ describe('Wave component', () => {
fireEvent.click(container.querySelector('button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('red');
expect(getWaveColor()).toEqual('rgb(255, 0, 0)');
unmount();
});
@ -297,8 +285,7 @@ describe('Wave component', () => {
fireEvent.click(container.querySelector('button')!);
waitRaf();
const style = getWaveStyle();
expect(style['--wave-color']).toEqual('red');
expect(getWaveColor()).toEqual('red');
unmount();
});

View File

@ -22,7 +22,7 @@ const AffixMounter: React.FC<AffixProps> = ({ getInstance, ...restProps }) => {
const container = useRef<HTMLDivElement>(null);
useEffect(() => {
if (container.current) {
container.current.addEventListener = jest
container.current.addEventListener = vi
.fn()
.mockImplementation((event: keyof HTMLElementEventMap, cb: (ev: Event) => void) => {
events[event] = cb;
@ -42,12 +42,12 @@ describe('Affix Render', () => {
rtlTest(Affix);
accessibilityTest(Affix);
const domMock = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
const domMock = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
const classRect: Record<string, DOMRect> = { container: { top: 0, bottom: 100 } as DOMRect };
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
beforeAll(() => {
@ -57,8 +57,8 @@ describe('Affix Render', () => {
});
afterEach(() => {
jest.useRealTimers();
jest.clearAllTimers();
vi.useRealTimers();
vi.clearAllTimers();
});
afterAll(() => {
@ -89,7 +89,11 @@ describe('Affix Render', () => {
});
it('Anchor correct render when target is null', async () => {
render(<Affix target={() => null}>test</Affix>);
render(
<Affix target={() => null}>
<span>test</span>
</Affix>,
);
await waitFakeTimer();
});
@ -109,7 +113,7 @@ describe('Affix Render', () => {
});
it('updatePosition when offsetTop changed', async () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container, rerender } = render(<AffixMounter offsetTop={0} onChange={onChange} />);
await waitFakeTimer();
@ -228,7 +232,7 @@ describe('Affix Render', () => {
'.fixed', // outer
].forEach((selector) => {
it(`trigger listener when size change: ${selector}`, async () => {
const updateCalled = jest.fn();
const updateCalled = vi.fn();
const { container } = render(
<AffixMounter offsetBottom={0} onTestUpdatePosition={updateCalled} />,
{

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Affix Render rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Affix Render > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div>
<div
class=""

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/affix/demo/basic.tsx extend context correctly 1`] = `
Array [

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/affix/demo/basic.tsx correctly 1`] = `
Array [

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/alert/demo/action.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/alert/demo/action.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Alert custom action 1`] = `
exports[`Alert > custom action 1`] = `
<div
class="ant-alert ant-alert-success"
data-show="true"
@ -74,7 +74,7 @@ exports[`Alert custom action 1`] = `
</div>
`;
exports[`Alert rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Alert > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-alert ant-alert-info ant-alert-no-icon ant-alert-rtl"
data-show="true"

View File

@ -3,7 +3,7 @@ import React from 'react';
import Alert from '..';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { act, render, screen } from '../../../tests/utils';
import { render, screen, waitFor } from '../../../tests/utils';
import Button from '../../button';
import Popconfirm from '../../popconfirm';
import Tooltip from '../../tooltip';
@ -15,15 +15,15 @@ describe('Alert', () => {
accessibilityTest(Alert);
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('should show close button and could be closed', async () => {
const onClose = jest.fn();
const onClose = vi.fn();
render(
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
@ -35,10 +35,6 @@ describe('Alert', () => {
await userEvent.click(screen.getByRole('button', { name: /close/i }));
act(() => {
jest.runAllTimers();
});
expect(onClose).toHaveBeenCalledTimes(1);
});
@ -76,7 +72,7 @@ describe('Alert', () => {
});
it('should show error as ErrorBoundary when children have error', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
expect(warnSpy).toHaveBeenCalledTimes(0);
// @ts-expect-error
// eslint-disable-next-line react/jsx-no-undef
@ -105,12 +101,10 @@ describe('Alert', () => {
await userEvent.hover(screen.getByRole('alert'));
act(() => {
jest.runAllTimers();
});
await waitFor(() => {
expect(screen.getByRole('tooltip')).toBeInTheDocument();
});
});
it('could be used with Popconfirm', async () => {
render(
@ -123,10 +117,6 @@ describe('Alert', () => {
);
await userEvent.click(screen.getByRole('alert'));
act(() => {
jest.runAllTimers();
});
expect(screen.getByRole('tooltip')).toBeInTheDocument();
});

View File

@ -2,6 +2,7 @@ import { resetWarned } from 'rc-util/lib/warning';
import React, { useState } from 'react';
import scrollIntoView from 'scroll-into-view-if-needed';
import type { SpyInstance } from 'vitest';
import Anchor from '..';
import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
@ -9,8 +10,9 @@ import type { AnchorDirection } from '../Anchor';
const { Link } = Anchor;
function createDiv() {
function createRootDiv() {
const root = document.createElement('div');
root.className = 'root';
document.body.appendChild(root);
return root;
}
@ -18,18 +20,16 @@ function createDiv() {
let idCounter = 0;
const getHashUrl = () => `Anchor-API-${idCounter++}`;
jest.mock('scroll-into-view-if-needed', () => jest.fn());
vi.mock('scroll-into-view-if-needed', () => ({
default: vi.fn(),
}));
describe('Anchor Render', () => {
const getBoundingClientRectMock = jest.spyOn(
HTMLHeadingElement.prototype,
'getBoundingClientRect',
);
const getClientRectsMock = jest.spyOn(HTMLHeadingElement.prototype, 'getClientRects');
const scrollIntoViewMock = jest.createMockFromModule<any>('scroll-into-view-if-needed');
const getBoundingClientRectMock = vi.spyOn(HTMLHeadingElement.prototype, 'getBoundingClientRect');
const getClientRectsMock = vi.spyOn(HTMLHeadingElement.prototype, 'getClientRects');
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
getBoundingClientRectMock.mockReturnValue({
width: 100,
height: 100,
@ -39,18 +39,18 @@ describe('Anchor Render', () => {
});
beforeEach(() => {
jest.useFakeTimers();
scrollIntoViewMock.mockReset();
vi.useFakeTimers();
vi.mocked(scrollIntoView).mockReset();
});
afterEach(() => {
jest.clearAllTimers();
jest.useRealTimers();
vi.clearAllTimers();
vi.useRealTimers();
});
afterAll(() => {
jest.clearAllTimers();
jest.useRealTimers();
vi.clearAllTimers();
vi.useRealTimers();
getBoundingClientRectMock.mockRestore();
getClientRectsMock.mockRestore();
});
@ -186,12 +186,12 @@ describe('Anchor Render', () => {
const link = container.querySelector(`a[href="http://www.example.com/#${hash}"]`)!;
fireEvent.click(link);
await waitFakeTimer();
expect(link.classList).toContain('ant-anchor-link-title-active');
expect(link.classList.contains('ant-anchor-link-title-active')).toBeTruthy();
});
it('scrolls the page when clicking a link', async () => {
const root = createDiv();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createRootDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
render(<div id="/faq?locale=en#Q1">Q1</div>, { container: root });
const { container } = render(
<Anchor items={[{ key: 'Q1', title: 'Q1', href: '/#/faq?locale=en#Q1' }]} />,
@ -200,13 +200,14 @@ describe('Anchor Render', () => {
fireEvent.click(link);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenCalled();
scrollToSpy.mockRestore();
});
it('handleScroll should not be triggered when scrolling caused by clicking a link', async () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const root = createDiv();
const onChange = jest.fn();
const root = createRootDiv();
const onChange = vi.fn();
render(
<div>
<div id={hash1}>Hello</div>
@ -265,8 +266,8 @@ describe('Anchor Render', () => {
it('targetOffset prop', async () => {
const hash = getHashUrl();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
const root = createRootDiv();
render(<h1 id={hash}>Hello</h1>, { container: root });
const { container, rerender } = render(
<Anchor items={[{ key: hash, href: `#${hash}`, title: hash }]} />,
@ -290,14 +291,16 @@ describe('Anchor Render', () => {
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
scrollToSpy.mockRestore();
});
// https://github.com/ant-design/ant-design/issues/31941
it('targetOffset prop when contain spaces', async () => {
const hash = `${getHashUrl()} s p a c e s`;
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
const root = createRootDiv();
render(<h1 id={hash}>Hello</h1>, { container: root });
const { container, rerender } = render(
<Anchor items={[{ key: hash, href: `#${hash}`, title: hash }]} />,
@ -319,6 +322,8 @@ describe('Anchor Render', () => {
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
scrollToSpy.mockRestore();
});
it('onClick event', () => {
@ -347,7 +352,7 @@ describe('Anchor Render', () => {
it('onChange event', () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Anchor
onChange={onChange}
@ -378,8 +383,8 @@ describe('Anchor Render', () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const beforeFn = jest.fn();
const afterFn = jest.fn();
const beforeFn = vi.fn();
const afterFn = vi.fn();
const Demo: React.FC = () => {
const [trigger, setTrigger] = useState(false);
@ -435,8 +440,8 @@ describe('Anchor Render', () => {
getBoundingClientRectMock.mockReturnValue({ width: 0, height: 0, top: 1000 } as DOMRect);
const hash = getHashUrl();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
const root = createRootDiv();
render(<h1 id={hash}>Hello</h1>, { container: root });
const { container, rerender } = render(
<Anchor>
@ -470,13 +475,14 @@ describe('Anchor Render', () => {
height: 100,
top: 1000,
} as DOMRect);
scrollToSpy.mockRestore();
});
it('test edge case when container is not windows', async () => {
const hash = getHashUrl();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createDiv();
const root = createRootDiv();
render(<h1 id={hash}>Hello</h1>, { container: root });
const { container, rerender } = render(
@ -492,19 +498,23 @@ describe('Anchor Render', () => {
</Anchor>,
);
// Since it's mock rect pos here. We need always reset the `scrollTop` for test
document.body.scrollTop = 0;
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
expect(document.body.scrollTop).toEqual(1000);
document.body.scrollTop = 0;
setProps({ offsetTop: 100 });
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
expect(document.body.scrollTop).toEqual(900);
document.body.scrollTop = 0;
setProps({ targetOffset: 200 });
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
expect(document.body.scrollTop).toEqual(800);
});
describe('getCurrentAnchor', () => {
@ -529,7 +539,7 @@ describe('Anchor Render', () => {
it('should trigger onChange when have getCurrentAnchor', () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Anchor
onChange={onChange}
@ -553,7 +563,7 @@ describe('Anchor Render', () => {
it('getCurrentAnchor have default link as argument', () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const getCurrentAnchor = jest.fn();
const getCurrentAnchor = vi.fn();
const { container } = render(
<Anchor
getCurrentAnchor={getCurrentAnchor}
@ -603,8 +613,8 @@ describe('Anchor Render', () => {
describe('scroll x', () => {
it('targetOffset horizontal', async () => {
const hash = getHashUrl();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
const root = createRootDiv();
render(<h1 id={hash}>Hello</h1>, { container: root });
const { container, rerender } = render(
<Anchor
@ -648,6 +658,8 @@ describe('Anchor Render', () => {
fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800);
scrollToSpy.mockRestore();
});
});
@ -756,12 +768,12 @@ describe('Anchor Render', () => {
const link = container.querySelector(`a[href="http://www.example.com/#${hash}"]`)!;
fireEvent.click(link);
await waitFakeTimer();
expect(link.classList).toContain('ant-anchor-link-title-active');
expect(link.classList.contains('ant-anchor-link-title-active')).toBeTruthy();
});
it('scrolls the page when clicking a link', async () => {
const root = createDiv();
const scrollToSpy = jest.spyOn(window, 'scrollTo');
const root = createRootDiv();
const scrollToSpy = vi.spyOn(window, 'scrollTo');
render(<div id="/faq?locale=en#Q1">Q1</div>, { container: root });
const { container } = render(
<Anchor>
@ -772,13 +784,15 @@ describe('Anchor Render', () => {
fireEvent.click(link);
await waitFakeTimer();
expect(scrollToSpy).toHaveBeenCalled();
scrollToSpy.mockRestore();
});
it('handleScroll should not be triggered when scrolling caused by clicking a link', async () => {
const hash1 = getHashUrl();
const hash2 = getHashUrl();
const root = createDiv();
const onChange = jest.fn();
const root = createRootDiv();
const onChange = vi.fn();
render(
<div>
<div id={hash1}>Hello</div>
@ -851,10 +865,10 @@ describe('Anchor Render', () => {
});
describe('warning', () => {
let errSpy: jest.SpyInstance;
let errSpy: SpyInstance;
beforeEach(() => {
resetWarned();
errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(() => {
@ -971,14 +985,14 @@ describe('Anchor Render', () => {
const toggleButton = wrapper.container.querySelector('button')!;
fireEvent.click(toggleButton);
act(() => jest.runAllTimers());
act(() => vi.runAllTimers());
expect(!!ink.style.left).toBe(true);
expect(!!ink.style.width).toBe(true);
expect(ink.style.top).toBe('');
expect(ink.style.height).toBe('');
fireEvent.click(toggleButton);
act(() => jest.runAllTimers());
act(() => vi.runAllTimers());
expect(!!ink.style.top).toBe(true);
expect(!!ink.style.height).toBe(true);
expect(ink.style.left).toBe('');

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Anchor Render render items and ignore jsx children 1`] = `
exports[`Anchor Render > render items and ignore jsx children 1`] = `
<div>
<div
class=""
@ -32,7 +32,7 @@ exports[`Anchor Render render items and ignore jsx children 1`] = `
</div>
`;
exports[`Anchor Render renders items correctly 1`] = `
exports[`Anchor Render > renders items correctly 1`] = `
<div>
<div
class=""
@ -108,7 +108,7 @@ exports[`Anchor Render renders items correctly 1`] = `
</div>
`;
exports[`Anchor Render renders items correctly#horizontal 1`] = `
exports[`Anchor Render > renders items correctly#horizontal 1`] = `
<div>
<div
class=""

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/anchor/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/anchor/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/app/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/app/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`App rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`App > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-app"
/>
`;
exports[`App single 1`] = `
exports[`App > single 1`] = `
<div
class="ant-app"
>

View File

@ -11,12 +11,12 @@ describe('App', () => {
rtlTest(App);
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.clearAllTimers();
jest.useRealTimers();
vi.clearAllTimers();
vi.useRealTimers();
});
it('single', () => {
@ -134,10 +134,12 @@ describe('App', () => {
it('support style', () => {
const { container } = render(
<App style={{ color: 'blue' }}>
<App style={{ color: 'rgb(255, 0, 0)' }}>
<div>test</div>
</App>,
);
expect(container.querySelector<HTMLDivElement>('.ant-app')).toHaveStyle('color: blue;');
expect(container.querySelector<HTMLDivElement>('.ant-app')).toHaveStyle(
'color: rgb(255, 0, 0);',
);
});
});

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/auto-complete/demo/basic.tsx extend context correctly 1`] = `
Array [
@ -235,7 +235,7 @@ exports[`renders components/auto-complete/demo/certain-category.tsx extend conte
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -1827,7 +1827,7 @@ exports[`renders components/auto-complete/demo/non-case-sensitive.tsx extend con
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -2028,7 +2028,7 @@ exports[`renders components/auto-complete/demo/render-panel.tsx extend context c
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/auto-complete/demo/basic.tsx correctly 1`] = `
Array [

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`AutoComplete rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`AutoComplete > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-select ant-select-rtl ant-select-auto-complete ant-select-single ant-select-show-search"
>

View File

@ -5,7 +5,7 @@ import { render } from '../../../tests/utils';
describe('AutoComplete children could be focus', () => {
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
let container: HTMLDivElement;
@ -15,7 +15,7 @@ describe('AutoComplete children could be focus', () => {
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
afterEach(() => {
@ -23,31 +23,31 @@ describe('AutoComplete children could be focus', () => {
});
it('focus() and onFocus', () => {
const handleFocus = jest.fn();
const handleFocus = vi.fn();
const { container: wrapper } = render(<AutoComplete onFocus={handleFocus} />, { container });
wrapper.querySelector('input')?.focus();
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(handleFocus).toHaveBeenCalled();
});
it('blur() and onBlur', () => {
const handleBlur = jest.fn();
const handleBlur = vi.fn();
const { container: wrapper } = render(<AutoComplete onBlur={handleBlur} />, { container });
wrapper.querySelector('input')?.focus();
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
wrapper.querySelector('input')?.blur();
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(handleBlur).toHaveBeenCalled();
});
it('child.ref should work', () => {
const mockRef = jest.fn();
const mockRef = vi.fn();
render(
<AutoComplete dataSource={[]}>
<input ref={mockRef} />

View File

@ -1,11 +1,11 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import AutoComplete from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render, screen } from '../../../tests/utils';
import Input from '../../input';
import { resetWarned } from '../../_util/warning';
import Input from '../../input';
describe('AutoComplete', () => {
mountTest(AutoComplete);
@ -49,7 +49,7 @@ describe('AutoComplete', () => {
});
it('AutoComplete throws error when contains invalid dataSource', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(
// @ts-ignore
@ -82,7 +82,7 @@ describe('AutoComplete', () => {
});
it('should not warning when getInputElement is null', () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
render(<AutoComplete placeholder="input here" allowClear />);
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
@ -100,7 +100,7 @@ describe('AutoComplete', () => {
it('deprecated dropdownClassName', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(
<AutoComplete
dropdownClassName="legacy"

View File

@ -178,7 +178,7 @@ const RefAutoComplete = React.forwardRef<RefSelectProps, AutoCompleteProps>(
};
// We don't care debug panel
/* istanbul ignore next */
/* c8 ignore next */
const PurePanel = genPurePanel(RefAutoComplete);
RefAutoComplete.Option = Option;

View File

@ -7,7 +7,7 @@ import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render } from '../../../tests/utils';
import useBreakpoint from '../../grid/hooks/useBreakpoint';
jest.mock('../../grid/hooks/useBreakpoint');
vi.mock('../../grid/hooks/useBreakpoint');
describe('Avatar Render', () => {
mountTest(Avatar);
@ -122,7 +122,7 @@ describe('Avatar Render', () => {
});
it('should warning when pass a string as icon props', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Avatar size={64} icon="aa" />);
expect(warnSpy).not.toHaveBeenCalled();
@ -152,7 +152,7 @@ describe('Avatar Render', () => {
});
it('support onMouseEnter', () => {
const onMouseEnter = jest.fn();
const onMouseEnter = vi.fn();
const { container } = render(<Avatar {...{ onMouseEnter }}>TestString</Avatar>);
fireEvent.mouseEnter(container.firstChild!);
expect(onMouseEnter).toHaveBeenCalled();
@ -191,7 +191,7 @@ describe('Avatar Render', () => {
});
it('clickable', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(<Avatar onClick={onClick}>TestString</Avatar>);
fireEvent.click(container.querySelector('.ant-avatar-string')!);
expect(onClick).toHaveBeenCalled();

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Avatar Render adjusts component size to 24 when window size is xs 1`] = `
exports[`Avatar Render > adjusts component size to 24 when window size is xs 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -14,7 +14,7 @@ exports[`Avatar Render adjusts component size to 24 when window size is xs 1`] =
</div>
`;
exports[`Avatar Render adjusts component size to 32 when window size is sm 1`] = `
exports[`Avatar Render > adjusts component size to 32 when window size is sm 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -28,7 +28,7 @@ exports[`Avatar Render adjusts component size to 32 when window size is sm 1`] =
</div>
`;
exports[`Avatar Render adjusts component size to 40 when window size is md 1`] = `
exports[`Avatar Render > adjusts component size to 40 when window size is md 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -42,7 +42,7 @@ exports[`Avatar Render adjusts component size to 40 when window size is md 1`] =
</div>
`;
exports[`Avatar Render adjusts component size to 64 when window size is lg 1`] = `
exports[`Avatar Render > adjusts component size to 64 when window size is lg 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -56,7 +56,7 @@ exports[`Avatar Render adjusts component size to 64 when window size is lg 1`] =
</div>
`;
exports[`Avatar Render adjusts component size to 80 when window size is xl 1`] = `
exports[`Avatar Render > adjusts component size to 80 when window size is xl 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -70,7 +70,7 @@ exports[`Avatar Render adjusts component size to 80 when window size is xl 1`] =
</div>
`;
exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`] = `
exports[`Avatar Render > adjusts component size to 100 when window size is xxl 1`] = `
<div>
<span
class="ant-avatar ant-avatar-circle"
@ -84,7 +84,7 @@ exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`]
</div>
`;
exports[`Avatar Render fallback 1`] = `
exports[`Avatar Render > fallback 1`] = `
<span
class="ant-avatar ant-avatar-circle"
>
@ -97,7 +97,7 @@ exports[`Avatar Render fallback 1`] = `
</span>
`;
exports[`Avatar Render rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Avatar Render > rtl render > component should be rendered correctly in RTL direction 1`] = `
<span
class="ant-avatar ant-avatar-circle"
>
@ -108,7 +108,7 @@ exports[`Avatar Render rtl render component should be rendered correctly in RTL
</span>
`;
exports[`Avatar Render should calculate scale of avatar children correctly 1`] = `
exports[`Avatar Render > should calculate scale of avatar children correctly 1`] = `
<span
class="ant-avatar-string"
style="transform: scale(0.72) translateX(-50%);"
@ -117,7 +117,7 @@ exports[`Avatar Render should calculate scale of avatar children correctly 1`] =
</span>
`;
exports[`Avatar Render should calculate scale of avatar children correctly 2`] = `
exports[`Avatar Render > should calculate scale of avatar children correctly 2`] = `
<span
class="ant-avatar-string"
style="transform: scale(0.72) translateX(-50%);"
@ -126,7 +126,7 @@ exports[`Avatar Render should calculate scale of avatar children correctly 2`] =
</span>
`;
exports[`Avatar Render should calculate scale of avatar children correctly with gap 1`] = `
exports[`Avatar Render > should calculate scale of avatar children correctly with gap 1`] = `
<span
class="ant-avatar-string"
style="transform: scale(0.36) translateX(-50%);"
@ -135,7 +135,7 @@ exports[`Avatar Render should calculate scale of avatar children correctly with
</span>
`;
exports[`Avatar Render should handle onError correctly 1`] = `
exports[`Avatar Render > should handle onError correctly 1`] = `
<span
class="ant-avatar ant-avatar-circle ant-avatar-image"
>
@ -145,7 +145,7 @@ exports[`Avatar Render should handle onError correctly 1`] = `
</span>
`;
exports[`Avatar Render should show image on success after a failure state 1`] = `
exports[`Avatar Render > should show image on success after a failure state 1`] = `
<span
class="ant-avatar ant-avatar-circle"
>
@ -158,7 +158,7 @@ exports[`Avatar Render should show image on success after a failure state 1`] =
</span>
`;
exports[`Avatar Render should show image on success after a failure state 2`] = `
exports[`Avatar Render > should show image on success after a failure state 2`] = `
<span
class="ant-avatar ant-avatar-circle ant-avatar-image"
>
@ -168,7 +168,7 @@ exports[`Avatar Render should show image on success after a failure state 2`] =
</span>
`;
exports[`Avatar Render support size is number 1`] = `
exports[`Avatar Render > support size is number 1`] = `
<span
class="ant-avatar ant-avatar-circle"
style="width: 100px; height: 100px; line-height: 100px; font-size: 18px;"

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/avatar/demo/badge.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/avatar/demo/badge.tsx correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/back-top/demo/basic.tsx extend context correctly 1`] = `
Array [

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/back-top/demo/basic.tsx correctly 1`] = `
Array [

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`BackTop rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`BackTop > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-back-top ant-back-top-rtl"
/>

View File

@ -6,17 +6,17 @@ import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
describe('BackTop', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});
mountTest(BackTop);
rtlTest(BackTop);
it('should scroll to top after click it', async () => {
const { container } = render(<BackTop />);
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
window.scrollY = y;
window.pageYOffset = y;
document.documentElement.scrollTop = y;
@ -31,20 +31,20 @@ describe('BackTop', () => {
});
it('support onClick', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(<BackTop onClick={onClick} visibilityHeight={0} />);
fireEvent.click(container.querySelector<HTMLDivElement>('.ant-back-top')!);
expect(onClick).toHaveBeenCalled();
});
it('invalid target', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(<BackTop onClick={onClick} target={undefined} />);
fireEvent.click(container.querySelector<HTMLDivElement>('.ant-back-top')!);
expect(onClick).toHaveBeenCalled();
});
it('should console Error', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<BackTop />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: BackTop] `BackTop` is deprecated, please use `FloatButton.BackTop` instead.',

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/badge/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/badge/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Badge render Badge status/color when contains children 1`] = `
exports[`Badge > render Badge status/color when contains children 1`] = `
<div>
<span
class="ant-badge"
@ -69,7 +69,7 @@ exports[`Badge render Badge status/color when contains children 1`] = `
</div>
`;
exports[`Badge render correct with negative number 1`] = `
exports[`Badge > render correct with negative number 1`] = `
<div>
<span
class="ant-badge ant-badge-not-a-wrapper"
@ -154,13 +154,13 @@ exports[`Badge render correct with negative number 1`] = `
</div>
`;
exports[`Badge rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Badge > rtl render > component should be rendered correctly in RTL direction 1`] = `
<span
class="ant-badge ant-badge-not-a-wrapper ant-badge-rtl"
/>
`;
exports[`Badge rtl render component should be rendered correctly in RTL direction 2`] = `
exports[`Badge > rtl render > component should be rendered correctly in RTL direction 2`] = `
<span
class="ant-badge ant-badge-rtl"
>
@ -190,7 +190,7 @@ exports[`Badge rtl render component should be rendered correctly in RTL directio
</span>
`;
exports[`Badge should be compatible with borderColor style 1`] = `
exports[`Badge > should be compatible with borderColor style 1`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -214,7 +214,7 @@ exports[`Badge should be compatible with borderColor style 1`] = `
</span>
`;
exports[`Badge should display custom color and number is 0 1`] = `
exports[`Badge > should display custom color and number is 0 1`] = `
<div>
<span
class="ant-badge ant-badge-not-a-wrapper"
@ -265,7 +265,7 @@ exports[`Badge should display custom color and number is 0 1`] = `
</div>
`;
exports[`Badge should render when count is changed 1`] = `
exports[`Badge > should render when count is changed 1`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -358,7 +358,7 @@ exports[`Badge should render when count is changed 1`] = `
</span>
`;
exports[`Badge should render when count is changed 2`] = `
exports[`Badge > should render when count is changed 2`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -451,7 +451,7 @@ exports[`Badge should render when count is changed 2`] = `
</span>
`;
exports[`Badge should render when count is changed 3`] = `
exports[`Badge > should render when count is changed 3`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -485,7 +485,7 @@ exports[`Badge should render when count is changed 3`] = `
</span>
`;
exports[`Badge should render when count is changed 4`] = `
exports[`Badge > should render when count is changed 4`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -499,7 +499,7 @@ exports[`Badge should render when count is changed 4`] = `
</span>
`;
exports[`Badge should render when count is changed 5`] = `
exports[`Badge > should render when count is changed 5`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -532,7 +532,7 @@ exports[`Badge should render when count is changed 5`] = `
</span>
`;
exports[`Badge should render when count is changed 6`] = `
exports[`Badge > should render when count is changed 6`] = `
<span
class="ant-badge ant-badge-not-a-wrapper"
>
@ -615,7 +615,7 @@ exports[`Badge should render when count is changed 6`] = `
</span>
`;
exports[`Badge should support offset when count is a ReactNode 1`] = `
exports[`Badge > should support offset when count is a ReactNode 1`] = `
<span
class="ant-badge"
>

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Ribbon rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Ribbon > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-ribbon-wrapper"
>

View File

@ -18,15 +18,15 @@ describe('Badge', () => {
));
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('no strict warning', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const { rerender } = render(
<Badge dot>
<span />
@ -83,7 +83,7 @@ describe('Badge', () => {
act(() => {
fireEvent.mouseEnter(container.querySelector('.ant-badge')!);
jest.runAllTimers();
vi.runAllTimers();
});
expect(container.querySelector('.ant-tooltip-open')).toBeTruthy();
});
@ -95,7 +95,7 @@ describe('Badge', () => {
rerender(<Badge count={count} />);
act(() => {
jest.runAllTimers();
vi.runAllTimers();
expect(asFragment().firstChild).toMatchSnapshot();
});
}

View File

@ -12,7 +12,7 @@ describe('Breadcrumb', () => {
rtlTest(Breadcrumb);
accessibilityTest(Breadcrumb);
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
afterEach(() => {
errorSpy.mockReset();
@ -326,7 +326,7 @@ describe('Breadcrumb', () => {
it('should console Error when `overlay` in props', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(
<Breadcrumb>
<Breadcrumb.Item overlay={<div>test</div>} />
@ -339,14 +339,14 @@ describe('Breadcrumb', () => {
});
it('should not console Error when `overlay` not in props', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Breadcrumb items={[{ path: '/', title: 'Test' }]} />);
expect(errSpy).not.toHaveBeenCalled();
errSpy.mockRestore();
});
it('should use `onClick`', async () => {
const onClick = jest.fn();
const onClick = vi.fn();
const wrapper = render(<Breadcrumb items={[{ title: 'test', onClick }]} />);
const item = await wrapper.findByText('test');
item.click();

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Breadcrumb filter React.Fragment 1`] = `
exports[`Breadcrumb > filter React.Fragment 1`] = `
<nav
class="ant-breadcrumb"
>
@ -36,7 +36,7 @@ exports[`Breadcrumb filter React.Fragment 1`] = `
</nav>
`;
exports[`Breadcrumb rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Breadcrumb > rtl render > component should be rendered correctly in RTL direction 1`] = `
<nav
class="ant-breadcrumb ant-breadcrumb-rtl"
>
@ -44,7 +44,7 @@ exports[`Breadcrumb rtl render component should be rendered correctly in RTL dir
</nav>
`;
exports[`Breadcrumb should accept undefined items 1`] = `
exports[`Breadcrumb > should accept undefined items 1`] = `
<nav
class="ant-breadcrumb"
>
@ -52,7 +52,7 @@ exports[`Breadcrumb should accept undefined items 1`] = `
</nav>
`;
exports[`Breadcrumb should allow Breadcrumb.Item is null or undefined 1`] = `
exports[`Breadcrumb > should allow Breadcrumb.Item is null or undefined 1`] = `
<nav
class="ant-breadcrumb"
>
@ -68,7 +68,7 @@ exports[`Breadcrumb should allow Breadcrumb.Item is null or undefined 1`] = `
</nav>
`;
exports[`Breadcrumb should not display Breadcrumb Item when its children is falsy 1`] = `
exports[`Breadcrumb > should not display Breadcrumb Item when its children is falsy 1`] = `
<nav
class="ant-breadcrumb"
>
@ -97,7 +97,7 @@ exports[`Breadcrumb should not display Breadcrumb Item when its children is fals
</nav>
`;
exports[`Breadcrumb should render a menu 1`] = `
exports[`Breadcrumb > should render a menu 1`] = `
<nav
class="ant-breadcrumb"
>
@ -177,7 +177,7 @@ exports[`Breadcrumb should render a menu 1`] = `
</nav>
`;
exports[`Breadcrumb should render correct 1`] = `
exports[`Breadcrumb > should render correct 1`] = `
<nav
class="ant-breadcrumb"
>
@ -209,7 +209,7 @@ exports[`Breadcrumb should render correct 1`] = `
</nav>
`;
exports[`Breadcrumb should support Breadcrumb.Item default separator 1`] = `
exports[`Breadcrumb > should support Breadcrumb.Item default separator 1`] = `
<nav
class="ant-breadcrumb"
>
@ -253,7 +253,7 @@ exports[`Breadcrumb should support Breadcrumb.Item default separator 1`] = `
</nav>
`;
exports[`Breadcrumb should support React.Fragment and falsy children 1`] = `
exports[`Breadcrumb > should support React.Fragment and falsy children 1`] = `
<nav
class="ant-breadcrumb"
>
@ -302,7 +302,7 @@ exports[`Breadcrumb should support React.Fragment and falsy children 1`] = `
</nav>
`;
exports[`Breadcrumb should support custom attribute 1`] = `
exports[`Breadcrumb > should support custom attribute 1`] = `
<nav
class="ant-breadcrumb"
data-custom="custom"
@ -333,7 +333,7 @@ exports[`Breadcrumb should support custom attribute 1`] = `
</nav>
`;
exports[`Breadcrumb should support string \`0\` and number \`0\` 1`] = `
exports[`Breadcrumb > should support string \`0\` and number \`0\` 1`] = `
<nav
class="ant-breadcrumb"
>

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/breadcrumb/demo/basic.tsx extend context correctly 1`] = `
<nav

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/breadcrumb/demo/basic.tsx correctly 1`] = `
<nav

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Breadcrumb.ItemRender render as expect 1`] = `
exports[`Breadcrumb.ItemRender > render as expect 1`] = `
<div>
<nav
class="ant-breadcrumb"

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`react router react router 3 1`] = `
exports[`react router > react router 3 1`] = `
<nav
class="ant-breadcrumb"
>

View File

@ -25,11 +25,11 @@ const breadcrumbNameMap = {
describe('react router', () => {
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('react router 6', () => {
@ -51,11 +51,11 @@ describe('react router', () => {
</Breadcrumb.Item>,
].concat(extraBreadcrumbItems);
const componentProps = useMemo<RouterProps>(
() => ({ component: Apps }) as unknown as RouterProps,
() => ({ component: Apps } as unknown as RouterProps),
[],
);
const renderProps = useMemo<RouterProps>(
() => ({ render: () => <span>Home Page</span> }) as unknown as RouterProps,
() => ({ render: () => <span>Home Page</span> } as unknown as RouterProps),
[],
);
return (

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/button/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/button/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Button fixbug renders {0} , 0 and {false} 1`] = `
exports[`Button > fixbug renders {0} , 0 and {false} 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -9,7 +9,7 @@ exports[`Button fixbug renders {0} , 0 and {false} 1`] = `
</button>
`;
exports[`Button fixbug renders {0} , 0 and {false} 2`] = `
exports[`Button > fixbug renders {0} , 0 and {false} 2`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -20,14 +20,14 @@ exports[`Button fixbug renders {0} , 0 and {false} 2`] = `
</button>
`;
exports[`Button fixbug renders {0} , 0 and {false} 3`] = `
exports[`Button > fixbug renders {0} , 0 and {false} 3`] = `
<button
class="ant-btn ant-btn-default"
type="button"
/>
`;
exports[`Button renders Chinese characters correctly 1`] = `
exports[`Button > renders Chinese characters correctly 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -38,7 +38,7 @@ exports[`Button renders Chinese characters correctly 1`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 2`] = `
exports[`Button > renders Chinese characters correctly 2`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -72,7 +72,7 @@ exports[`Button renders Chinese characters correctly 2`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 3`] = `
exports[`Button > renders Chinese characters correctly 3`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -102,7 +102,7 @@ exports[`Button renders Chinese characters correctly 3`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 4`] = `
exports[`Button > renders Chinese characters correctly 4`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -136,7 +136,7 @@ exports[`Button renders Chinese characters correctly 4`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 5`] = `
exports[`Button > renders Chinese characters correctly 5`] = `
<button
class="ant-btn ant-btn-default ant-btn-loading"
type="button"
@ -170,7 +170,7 @@ exports[`Button renders Chinese characters correctly 5`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 6`] = `
exports[`Button > renders Chinese characters correctly 6`] = `
<button
class="ant-btn ant-btn-default ant-btn-loading"
type="button"
@ -205,7 +205,7 @@ exports[`Button renders Chinese characters correctly 6`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 7`] = `
exports[`Button > renders Chinese characters correctly 7`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -216,7 +216,7 @@ exports[`Button renders Chinese characters correctly 7`] = `
</button>
`;
exports[`Button renders correctly 1`] = `
exports[`Button > renders correctly 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -227,52 +227,52 @@ exports[`Button renders correctly 1`] = `
</button>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 1`] = `
<button
class="ant-btn ant-btn-default ant-btn-rtl"
type="button"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 2`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 2`] = `
<button
class="ant-btn ant-btn-default ant-btn-lg ant-btn-rtl"
type="button"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 3`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 3`] = `
<button
class="ant-btn ant-btn-default ant-btn-sm ant-btn-rtl"
type="button"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 4`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 4`] = `
<div
class="ant-btn-group ant-btn-group-rtl"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 5`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 5`] = `
<div
class="ant-btn-group ant-btn-group-lg ant-btn-group-rtl"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 6`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 6`] = `
<div
class="ant-btn-group ant-btn-group-sm ant-btn-group-rtl"
/>
`;
exports[`Button rtl render component should be rendered correctly in RTL direction 7`] = `
exports[`Button > rtl render > component should be rendered correctly in RTL direction 7`] = `
<div
class="ant-btn-group ant-btn-group-rtl"
/>
`;
exports[`Button should handle fragment as children 1`] = `
exports[`Button > should handle fragment as children 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -283,7 +283,7 @@ exports[`Button should handle fragment as children 1`] = `
</button>
`;
exports[`Button should merge text if children using variable 1`] = `
exports[`Button > should merge text if children using variable 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
@ -294,7 +294,7 @@ exports[`Button should merge text if children using variable 1`] = `
</button>
`;
exports[`Button should not render as link button when href is undefined 1`] = `
exports[`Button > should not render as link button when href is undefined 1`] = `
<button
class="ant-btn ant-btn-primary"
type="button"
@ -305,14 +305,14 @@ exports[`Button should not render as link button when href is undefined 1`] = `
</button>
`;
exports[`Button should render empty button without errors 1`] = `
exports[`Button > should render empty button without errors 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
/>
`;
exports[`Button should support custom icon className 1`] = `
exports[`Button > should support custom icon className 1`] = `
<div>
<button
class="ant-btn ant-btn-primary ant-btn-icon-only"
@ -345,7 +345,7 @@ exports[`Button should support custom icon className 1`] = `
</div>
`;
exports[`Button should support custom icon styles 1`] = `
exports[`Button > should support custom icon styles 1`] = `
<div>
<button
class="ant-btn ant-btn-primary ant-btn-icon-only"
@ -379,7 +379,7 @@ exports[`Button should support custom icon styles 1`] = `
</div>
`;
exports[`Button should support link button 1`] = `
exports[`Button > should support link button 1`] = `
<a
class="ant-btn ant-btn-default"
href="https://ant.design"

View File

@ -30,16 +30,16 @@ const Content = () => {
it('Delay loading timer in Button component', () => {
const otherTimer = 9528;
jest.spyOn<Window, 'setTimeout'>(window, 'setTimeout').mockReturnValue(otherTimer);
jest.restoreAllMocks();
vi.spyOn<Window, 'setTimeout'>(window, 'setTimeout').mockReturnValue(otherTimer);
vi.restoreAllMocks();
const wrapper = render(<Content />);
const btnTimer = 9527;
const setTimeoutMock = jest
const setTimeoutMock = vi
.spyOn<Window, 'setTimeout'>(window, 'setTimeout')
.mockReturnValue(btnTimer);
const clearTimeoutMock = jest.spyOn<Window, 'clearTimeout'>(window, 'clearTimeout');
const clearTimeoutMock = vi.spyOn<Window, 'clearTimeout'>(window, 'clearTimeout');
// other component may call setTimeout or clearTimeout
const setTimeoutCount = () => {
@ -89,7 +89,7 @@ it('Delay loading timer in Button component', () => {
expect(setTimeoutCount()).toBe(3);
expect(clearTimeoutCount()).toBe(2);
jest.restoreAllMocks();
vi.restoreAllMocks();
});
it('Delay loading while use loading delay at first time', () => {
const Demo = () => <Button loading={{ delay: specialDelay }} />;

View File

@ -37,7 +37,7 @@ describe('Button', () => {
it('warns if size is wrong', () => {
resetWarned();
const mockWarn = jest.spyOn(console, 'error').mockImplementation(() => {});
const mockWarn = vi.spyOn(console, 'error').mockImplementation(() => {});
const size = 'who am I';
// @ts-expect-error: Type '"who am I"' is not assignable to type 'SizeType'.ts(2322)
render(<Button.Group size={size} />);
@ -177,22 +177,22 @@ describe('Button', () => {
});
it('reset when loading back of delay', () => {
jest.useFakeTimers();
vi.useFakeTimers();
const { rerender, container } = render(<Button loading={{ delay: 1000 }} />);
rerender(<Button loading={{ delay: 2000 }} />);
rerender(<Button loading={false} />);
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(container.querySelectorAll('.ant-btn-loading')).toHaveLength(0);
jest.useRealTimers();
vi.useRealTimers();
});
it('should not clickable when button is loading', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(
<Button loading onClick={onClick}>
button
@ -238,7 +238,7 @@ describe('Button', () => {
});
it('should support to change loading', async () => {
jest.useFakeTimers();
vi.useFakeTimers();
const { container, rerender, unmount } = render(<Button>Button</Button>);
rerender(<Button loading />);
expect(container.querySelectorAll('.ant-btn-loading').length).toBe(1);
@ -252,12 +252,12 @@ describe('Button', () => {
await waitFakeTimer();
expect(container.querySelectorAll('.ant-btn-loading').length).toBe(0);
expect(unmount).not.toThrow();
jest.useRealTimers();
vi.useRealTimers();
});
it('should warning when pass a string as icon props', () => {
resetWarned();
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Button type="primary" icon="ab" />);
expect(warnSpy).not.toHaveBeenCalled();
@ -272,7 +272,7 @@ describe('Button', () => {
it('should warning when pass type=link and ghost=true', () => {
resetWarned();
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Button type="link" ghost />);
expect(warnSpy).toHaveBeenCalledWith(
"Warning: [antd: Button] `link` or `text` button can't be a `ghost` button.",
@ -282,7 +282,7 @@ describe('Button', () => {
it('should warning when pass type=text and ghost=true', () => {
resetWarned();
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Button type="text" ghost />);
expect(warnSpy).toHaveBeenCalledWith(
"Warning: [antd: Button] `link` or `text` button can't be a `ghost` button.",
@ -305,7 +305,7 @@ describe('Button', () => {
});
it('should not redirect when button is disabled', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(
<Button href="https://ant.design" onClick={onClick} disabled>
click me

View File

@ -3,28 +3,26 @@ import React from 'react';
import Button from '..';
import { act, fireEvent, render } from '../../../tests/utils';
jest.mock('rc-util/lib/Dom/isVisible', () => {
const mockFn = () => true;
return mockFn;
});
vi.mock('rc-util/es/Dom/isVisible', () => ({ default: () => true }));
describe('click wave effect', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.clearAllTimers();
jest.useRealTimers();
afterEach(async () => {
await vi.runAllTimersAsync();
vi.clearAllTimers();
vi.useRealTimers();
document.body.innerHTML = '';
});
async function clickButton(container: HTMLElement) {
const element = container.firstChild;
// https://github.com/testing-library/user-event/issues/833
await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(element as Element);
await userEvent.setup({ advanceTimers: vi.advanceTimersByTime }).click(element as Element);
act(() => {
jest.advanceTimersByTime(100);
vi.advanceTimersByTime(100);
});
fireEvent(element!, new Event('transitionstart'));

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/calendar/demo/basic.tsx extend context correctly 1`] = `
<div
@ -74,7 +74,7 @@ exports[`renders components/calendar/demo/basic.tsx extend context correctly 1`]
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -521,7 +521,7 @@ exports[`renders components/calendar/demo/basic.tsx extend context correctly 1`]
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -1659,7 +1659,7 @@ exports[`renders components/calendar/demo/card.tsx extend context correctly 1`]
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -2106,7 +2106,7 @@ exports[`renders components/calendar/demo/card.tsx extend context correctly 1`]
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -3243,7 +3243,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -3690,7 +3690,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -4823,7 +4823,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -5270,7 +5270,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -6448,7 +6448,7 @@ exports[`renders components/calendar/demo/customize-header.tsx extend context co
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -6920,7 +6920,7 @@ exports[`renders components/calendar/demo/customize-header.tsx extend context co
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -8041,7 +8041,7 @@ exports[`renders components/calendar/demo/notice-calendar.tsx extend context cor
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -8488,7 +8488,7 @@ exports[`renders components/calendar/demo/notice-calendar.tsx extend context cor
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -10036,7 +10036,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div
@ -10483,7 +10483,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/calendar/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Calendar Calendar MonthSelect should display correct label 1`] = `
exports[`Calendar > Calendar MonthSelect should display correct label 1`] = `
<div
class="ant-picker-calendar ant-picker-calendar-full"
>
@ -946,7 +946,7 @@ exports[`Calendar Calendar MonthSelect should display correct label 1`] = `
</div>
`;
exports[`Calendar Calendar should support locale 1`] = `
exports[`Calendar > Calendar should support locale 1`] = `
<div
class="ant-picker-calendar ant-picker-calendar-full"
>
@ -1892,7 +1892,7 @@ exports[`Calendar Calendar should support locale 1`] = `
</div>
`;
exports[`Calendar rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Calendar > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-picker-calendar ant-picker-calendar-full ant-picker-calendar-rtl"
>
@ -2838,7 +2838,7 @@ exports[`Calendar rtl render component should be rendered correctly in RTL direc
</div>
`;
exports[`Calendar support Calendar.generateCalendar 1`] = `
exports[`Calendar > support Calendar.generateCalendar 1`] = `
<div
class="ant-picker-calendar ant-picker-calendar-full"
>

View File

@ -20,17 +20,19 @@ const ref: {
calendarHeaderProps?: CalendarHeaderProps<unknown>;
} = {};
jest.mock('../Header', () => {
const HeaderModule = jest.requireActual('../Header');
vi.mock('../Header', async (importOriginal) => {
const HeaderModule = await importOriginal<typeof import('../Header')>();
const HeaderComponent = HeaderModule.default;
return (props: CalendarHeaderProps<any>) => {
return {
default: (props: CalendarHeaderProps<any>) => {
ref.calendarHeaderProps = props;
return <HeaderComponent {...props} />;
},
};
});
jest.mock('rc-picker', () => {
const RcPicker = jest.requireActual('rc-picker');
vi.mock('rc-picker', async () => {
const RcPicker = await vi.importActual<typeof import('rc-picker')>('rc-picker');
const PickerPanelComponent = RcPicker.PickerPanel;
return {
...RcPicker,
@ -71,8 +73,8 @@ describe('Calendar', () => {
it('Calendar should be selectable', () => {
MockDate.set(Dayjs('2000-01-01').valueOf());
const onSelect = jest.fn();
const onChange = jest.fn();
const onSelect = vi.fn();
const onChange = vi.fn();
const { container } = render(<Calendar onSelect={onSelect} onChange={onChange} />);
fireEvent.click(container.querySelector('.ant-picker-cell')!);
@ -87,7 +89,7 @@ describe('Calendar', () => {
});
it('only Valid range should be selectable', () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const validRange: [Dayjs.Dayjs, Dayjs.Dayjs] = [Dayjs('2018-02-02'), Dayjs('2018-02-18')];
const wrapper = render(
<Calendar onSelect={onSelect} validRange={validRange} defaultValue={Dayjs('2018-02-02')} />,
@ -98,7 +100,7 @@ describe('Calendar', () => {
});
it('dates other than in valid range should be disabled', () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const validRange: [Dayjs.Dayjs, Dayjs.Dayjs] = [Dayjs('2018-02-02'), Dayjs('2018-02-18')];
const { container } = render(
<Calendar onSelect={onSelect} validRange={validRange} defaultValue={Dayjs('2018-02-02')} />,
@ -112,7 +114,7 @@ describe('Calendar', () => {
});
it('months other than in valid range should be disabled', () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const validRange: [Dayjs.Dayjs, Dayjs.Dayjs] = [Dayjs('2018-02-02'), Dayjs('2018-05-18')];
const { container } = render(
<Calendar
@ -187,7 +189,7 @@ describe('Calendar', () => {
it('Calendar should switch mode', () => {
const monthMode = 'month';
const yearMode = 'year';
const onPanelChangeStub = jest.fn();
const onPanelChangeStub = vi.fn();
const wrapper = render(<Calendar mode={yearMode} onPanelChange={onPanelChangeStub} />);
expect(ref.calendarHeaderProps?.mode).toEqual(yearMode);
wrapper.rerender(<Calendar mode={monthMode} onPanelChange={onPanelChangeStub} />);
@ -195,10 +197,10 @@ describe('Calendar', () => {
expect(onPanelChangeStub).toHaveBeenCalledTimes(0);
});
it('Calendar should support locale', () => {
it('Calendar should support locale', async () => {
MockDate.set(Dayjs('2018-10-19').valueOf());
// eslint-disable-next-line global-require
const zhCN = require('../locale/zh_CN').default;
const zhCN = (await import('../locale/zh_CN')).default;
const wrapper = render(<Calendar locale={zhCN} />);
expect(wrapper.container.children[0]).toMatchSnapshot();
MockDate.reset();
@ -206,7 +208,7 @@ describe('Calendar', () => {
describe('onPanelChange', () => {
it('trigger when click last month of date', () => {
const onPanelChange = jest.fn();
const onPanelChange = vi.fn();
const date = Dayjs('1990-09-03');
const wrapper = render(<Calendar onPanelChange={onPanelChange} value={date} />);
@ -217,7 +219,7 @@ describe('Calendar', () => {
});
it('not trigger when in same month', () => {
const onPanelChange = jest.fn();
const onPanelChange = vi.fn();
const date = Dayjs('1990-09-03');
const wrapper = render(<Calendar onPanelChange={onPanelChange} value={date} />);
@ -228,7 +230,7 @@ describe('Calendar', () => {
});
it('switch should work correctly without prop mode', async () => {
const onPanelChange = jest.fn();
const onPanelChange = vi.fn();
const date = Dayjs(new Date(Date.UTC(2017, 7, 9, 8)));
const wrapper = render(<Calendar onPanelChange={onPanelChange} value={date} />);
@ -268,7 +270,7 @@ describe('Calendar', () => {
const value = Dayjs('1990-01-03');
const start = Dayjs('2019-04-01');
const end = Dayjs('2019-11-01');
const onValueChange = jest.fn();
const onValueChange = vi.fn();
createWrapper(start, end, value, onValueChange);
expect(onValueChange).toHaveBeenCalledWith(value.year(2019).month(3), 'year');
});
@ -277,7 +279,7 @@ describe('Calendar', () => {
const value = Dayjs('1990-01-03');
const start = Dayjs('2019-11-01');
const end = Dayjs('2019-03-01');
const onValueChange = jest.fn();
const onValueChange = vi.fn();
createWrapper(start, end, value, onValueChange);
expect(onValueChange).toHaveBeenCalledWith(value.year(2019).month(10), 'year');
});
@ -286,7 +288,7 @@ describe('Calendar', () => {
const value = Dayjs('2018-11-03');
const start = Dayjs('2000-01-01');
const end = Dayjs('2019-03-01');
const onValueChange = jest.fn();
const onValueChange = vi.fn();
const wrapper = render(
<Header
prefixCls="ant-picker-calendar"
@ -309,7 +311,7 @@ describe('Calendar', () => {
const start = Dayjs('2018-11-01');
const end = Dayjs('2019-03-01');
const value = Dayjs('2018-12-03');
const onValueChange = jest.fn();
const onValueChange = vi.fn();
const wrapper = render(
<Header
prefixCls="ant-picker-calendar"
@ -328,7 +330,7 @@ describe('Calendar', () => {
});
it('onTypeChange should work correctly', () => {
const onTypeChange = jest.fn();
const onTypeChange = vi.fn();
const value = Dayjs('2018-12-03');
const wrapper = render(
<Header
@ -348,12 +350,12 @@ describe('Calendar', () => {
});
it('headerRender should work correctly', () => {
const onMonthChange = jest.fn();
const onYearChange = jest.fn();
const onTypeChange = jest.fn();
const onMonthChange = vi.fn();
const onYearChange = vi.fn();
const onTypeChange = vi.fn();
// Year
const headerRender = jest.fn(({ value }) => {
const headerRender = vi.fn(({ value }) => {
const year = value.year();
const options = [];
for (let i = year - 100; i < year + 100; i += 1) {
@ -387,7 +389,7 @@ describe('Calendar', () => {
expect(onYearChange).toHaveBeenCalled();
// Month
const headerRenderWithMonth = jest.fn(({ value }) => {
const headerRenderWithMonth = vi.fn(({ value }) => {
const start = 0;
const end = 12;
const monthOptions = [];
@ -430,7 +432,7 @@ describe('Calendar', () => {
expect(onMonthChange).toHaveBeenCalled();
// Type
const headerRenderWithTypeChange = jest.fn(({ type }) => (
const headerRenderWithTypeChange = vi.fn(({ type }) => (
<Group size="small" onChange={onTypeChange} value={type}>
<Button value="month">Month</Button>
<Button value="year">Year</Button>
@ -478,7 +480,7 @@ describe('Calendar', () => {
});
it('when fullscreen is false, the element returned by dateFullCellRender should be interactive', () => {
const onClick = jest.fn();
const onClick = vi.fn();
const { container } = render(
<Calendar
fullscreen={false}
@ -496,7 +498,7 @@ describe('Calendar', () => {
it('deprecated dateCellRender and monthCellRender', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(
<Calendar
dateCellRender={() => <div className="bamboo">Light</div>}
@ -520,7 +522,7 @@ describe('Calendar', () => {
it('deprecated dateFullCellRender and monthFullCellRender', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(
<Calendar
dateFullCellRender={() => <div className="bamboo">Light</div>}
@ -540,12 +542,12 @@ describe('Calendar', () => {
});
it('support Calendar.generateCalendar', () => {
jest.useFakeTimers().setSystemTime(new Date('2000-01-01'));
vi.useFakeTimers().setSystemTime(new Date('2000-01-01'));
const MyCalendar = Calendar.generateCalendar(dayjsGenerateConfig);
const { container } = render(<MyCalendar />);
expect(container.firstChild).toMatchSnapshot();
jest.useRealTimers();
vi.useRealTimers();
});
});

View File

@ -13,16 +13,16 @@ describe('Calendar.onSelect', () => {
beforeEach(() => {
resetWarned();
jest.useFakeTimers();
jest.clearAllTimers();
vi.useFakeTimers();
vi.clearAllTimers();
});
afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('source of year select', async () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const { container } = render(<Calendar onSelect={onSelect} />);
fireEvent.mouseDown(container.querySelector('.ant-select-selector')!);
@ -35,20 +35,20 @@ describe('Calendar.onSelect', () => {
});
it('source of month select', async () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const { container } = render(<Calendar onSelect={onSelect} />);
fireEvent.mouseDown(container.querySelectorAll('.ant-select-selector')[1]!);
await waitFakeTimer();
fireEvent.click(container.querySelector('.ant-select-item-option')!);
fireEvent.click(container.querySelectorAll('.ant-select-item-option')[1]!);
await waitFakeTimer();
expect(onSelect).toHaveBeenCalledWith(expect.anything(), { source: 'month' });
});
it('source of customize', async () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const { container } = render(
<Calendar
onSelect={onSelect}
@ -73,7 +73,7 @@ describe('Calendar.onSelect', () => {
});
it('source of date', () => {
const onSelect = jest.fn();
const onSelect = vi.fn();
const { container } = render(<Calendar onSelect={onSelect} />);
fireEvent.click(container.querySelector('.ant-picker-cell')!);
@ -81,8 +81,8 @@ describe('Calendar.onSelect', () => {
});
it('source of date with month panel', async () => {
const onSelect = jest.fn();
const onPanelChange = jest.fn();
const onSelect = vi.fn();
const onPanelChange = vi.fn();
const { container } = render(<Calendar onSelect={onSelect} onPanelChange={onPanelChange} />);
// Default is month radio

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/card/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/card/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Card correct pass tabList props 1`] = `
exports[`Card > correct pass tabList props 1`] = `
<div
class="ant-card ant-card-bordered ant-card-contain-tabs"
>
@ -263,7 +263,7 @@ exports[`Card correct pass tabList props 1`] = `
</div>
`;
exports[`Card rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Card > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-card ant-card-bordered ant-card-rtl"
>
@ -273,7 +273,7 @@ exports[`Card rtl render component should be rendered correctly in RTL direction
</div>
`;
exports[`Card should still have padding when card which set padding to 0 is loading 1`] = `
exports[`Card > should still have padding when card which set padding to 0 is loading 1`] = `
<div
class="ant-card ant-card-loading ant-card-bordered"
>
@ -303,7 +303,7 @@ exports[`Card should still have padding when card which set padding to 0 is load
</div>
`;
exports[`Card title should be vertically aligned 1`] = `
exports[`Card > title should be vertically aligned 1`] = `
<div
class="ant-card ant-card-bordered"
style="width: 300px;"

View File

@ -12,11 +12,11 @@ describe('Card', () => {
rtlTest(Card);
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('should still have padding when card which set padding to 0 is loading', () => {
@ -48,7 +48,7 @@ describe('Card', () => {
tab: 'tab2',
},
];
const onTabChange = jest.fn();
const onTabChange = vi.fn();
render(
<Card onTabChange={onTabChange} tabList={tabList}>
xxx

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/carousel/demo/autoplay.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/carousel/demo/autoplay.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Carousel rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Carousel > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-carousel ant-carousel-rtl"
>
@ -19,7 +19,7 @@ exports[`Carousel rtl render component should be rendered correctly in RTL direc
</div>
`;
exports[`Carousel should works for dotPosition bottom 1`] = `
exports[`Carousel > should works for dotPosition > bottom 1`] = `
<div
class="ant-carousel"
>
@ -53,7 +53,7 @@ exports[`Carousel should works for dotPosition bottom 1`] = `
</div>
`;
exports[`Carousel should works for dotPosition left 1`] = `
exports[`Carousel > should works for dotPosition > left 1`] = `
<div
class="ant-carousel ant-carousel-vertical"
>
@ -87,7 +87,7 @@ exports[`Carousel should works for dotPosition left 1`] = `
</div>
`;
exports[`Carousel should works for dotPosition right 1`] = `
exports[`Carousel > should works for dotPosition > right 1`] = `
<div
class="ant-carousel ant-carousel-vertical"
>
@ -121,7 +121,7 @@ exports[`Carousel should works for dotPosition right 1`] = `
</div>
`;
exports[`Carousel should works for dotPosition top 1`] = `
exports[`Carousel > should works for dotPosition > top 1`] = `
<div
class="ant-carousel"
>

View File

@ -3,18 +3,18 @@ import type { CarouselRef } from '..';
import Carousel from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { waitFakeTimer, render } from '../../../tests/utils';
import { render, waitFakeTimer } from '../../../tests/utils';
describe('Carousel', () => {
mountTest(Carousel);
rtlTest(Carousel);
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});
it('should has innerSlider', () => {
@ -65,7 +65,7 @@ describe('Carousel', () => {
<div>3</div>
</Carousel>,
);
const spy = jest.spyOn(ref.current?.innerSlider, 'autoPlay');
const spy = vi.spyOn(ref.current?.innerSlider, 'autoPlay');
window.resizeTo(1000, window.outerHeight);
expect(spy).not.toHaveBeenCalled();
await waitFakeTimer();
@ -80,14 +80,13 @@ describe('Carousel', () => {
<div>3</div>
</Carousel>,
);
const spy = jest.spyOn(window, 'removeEventListener');
const spy = vi.spyOn(window, 'removeEventListener');
unmount();
expect(spy).toHaveBeenCalled();
});
describe('should works for dotPosition', () => {
(['left', 'right', 'top', 'bottom'] as const).forEach((dotPosition) => {
// eslint-disable-next-line jest/valid-title
it(dotPosition, () => {
const { container } = render(
<Carousel dotPosition={dotPosition}>

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/cascader/demo/basic.tsx extend context correctly 1`] = `
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/cascader/demo/basic.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Cascader can be selected 1`] = `
exports[`Cascader > can be selected 1`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -132,7 +132,7 @@ exports[`Cascader can be selected 1`] = `
</div>
`;
exports[`Cascader can be selected 2`] = `
exports[`Cascader > can be selected 2`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -282,7 +282,7 @@ exports[`Cascader can be selected 2`] = `
</div>
`;
exports[`Cascader can be selected 3`] = `
exports[`Cascader > can be selected 3`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -432,7 +432,7 @@ exports[`Cascader can be selected 3`] = `
</div>
`;
exports[`Cascader can be selected in RTL direction 1`] = `
exports[`Cascader > can be selected in RTL direction 1`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-cascader-dropdown-rtl ant-select-dropdown-placement-bottomRight"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -564,7 +564,7 @@ exports[`Cascader can be selected in RTL direction 1`] = `
</div>
`;
exports[`Cascader can be selected in RTL direction 2`] = `
exports[`Cascader > can be selected in RTL direction 2`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-cascader-dropdown-rtl ant-select-dropdown-placement-bottomRight"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -714,7 +714,7 @@ exports[`Cascader can be selected in RTL direction 2`] = `
</div>
`;
exports[`Cascader can be selected in RTL direction 3`] = `
exports[`Cascader > can be selected in RTL direction 3`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-cascader-dropdown-rtl ant-select-dropdown-placement-bottomRight"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -864,7 +864,7 @@ exports[`Cascader can be selected in RTL direction 3`] = `
</div>
`;
exports[`Cascader legacy props should support showCheckedStrategy child 1`] = `
exports[`Cascader > legacy props > should support showCheckedStrategy child 1`] = `
<div
class="ant-select ant-cascader ant-select-multiple ant-select-allow-clear ant-select-show-arrow ant-select-open"
>
@ -1041,7 +1041,7 @@ exports[`Cascader legacy props should support showCheckedStrategy child 1`] = `
</div>
`;
exports[`Cascader legacy props should support showCheckedStrategy parent 1`] = `
exports[`Cascader > legacy props > should support showCheckedStrategy parent 1`] = `
<div
class="ant-select ant-cascader ant-select-multiple ant-select-allow-clear ant-select-show-arrow ant-select-open"
>
@ -1218,7 +1218,7 @@ exports[`Cascader legacy props should support showCheckedStrategy parent 1`] = `
</div>
`;
exports[`Cascader popup correctly with defaultValue 1`] = `
exports[`Cascader > popup correctly with defaultValue 1`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: auto;"
@ -1368,7 +1368,7 @@ exports[`Cascader popup correctly with defaultValue 1`] = `
</div>
`;
exports[`Cascader popup correctly with defaultValue RTL 1`] = `
exports[`Cascader > popup correctly with defaultValue RTL 1`] = `
<div
class="ant-select ant-cascader ant-select-rtl ant-select-single ant-select-allow-clear ant-select-show-arrow ant-select-open"
>
@ -1604,7 +1604,7 @@ exports[`Cascader popup correctly with defaultValue RTL 1`] = `
</div>
`;
exports[`Cascader rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Cascader > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-select ant-cascader ant-select-rtl ant-select-single ant-select-allow-clear ant-select-show-arrow"
>
@ -1664,11 +1664,11 @@ exports[`Cascader rtl render component should be rendered correctly in RTL direc
</div>
`;
exports[`Cascader should highlight keyword and filter when search in Cascader 1`] = `"<div><div class="ant-cascader-menus"><ul class="ant-cascader-menu" role="menu"><li class="ant-cascader-menu-item" role="menuitemcheckbox" aria-checked="false" data-path-key="zhejiang__RC_CASCADER_SPLIT__hangzhou__RC_CASCADER_SPLIT__xihu"><div class="ant-cascader-menu-item-content"><span class="ant-cascader-menu-item-keyword">Z</span>hejiang / Hang<span class="ant-cascader-menu-item-keyword">z</span>hou / West Lake</div></li><li class="ant-cascader-menu-item" role="menuitemcheckbox" aria-checked="false" data-path-key="jiangsu__RC_CASCADER_SPLIT__nanjing__RC_CASCADER_SPLIT__zhonghuamen"><div class="ant-cascader-menu-item-content">Jiangsu / Nanjing / <span class="ant-cascader-menu-item-keyword">Z</span>hong Hua Men</div></li></ul></div></div>"`;
exports[`Cascader > should highlight keyword and filter when search in Cascader 1`] = `"<div><div class=\\"ant-cascader-menus\\"><ul class=\\"ant-cascader-menu\\" role=\\"menu\\"><li class=\\"ant-cascader-menu-item\\" role=\\"menuitemcheckbox\\" aria-checked=\\"false\\" data-path-key=\\"zhejiang__RC_CASCADER_SPLIT__hangzhou__RC_CASCADER_SPLIT__xihu\\"><div class=\\"ant-cascader-menu-item-content\\"><span class=\\"ant-cascader-menu-item-keyword\\">Z</span>hejiang / Hang<span class=\\"ant-cascader-menu-item-keyword\\">z</span>hou / West Lake</div></li><li class=\\"ant-cascader-menu-item\\" role=\\"menuitemcheckbox\\" aria-checked=\\"false\\" data-path-key=\\"jiangsu__RC_CASCADER_SPLIT__nanjing__RC_CASCADER_SPLIT__zhonghuamen\\"><div class=\\"ant-cascader-menu-item-content\\">Jiangsu / Nanjing / <span class=\\"ant-cascader-menu-item-keyword\\">Z</span>hong Hua Men</div></li></ul></div></div>"`;
exports[`Cascader should highlight keyword and filter when search in Cascader with same field name of label and value 1`] = `"<div><div class="ant-cascader-menus"><ul class="ant-cascader-menu" role="menu"><li class="ant-cascader-menu-item" role="menuitemcheckbox" aria-checked="false" data-path-key="Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__West Lake"><div class="ant-cascader-menu-item-content"><span class="ant-cascader-menu-item-keyword">Z</span>hejiang / Hang<span class="ant-cascader-menu-item-keyword">z</span>hou / West Lake</div></li><li class="ant-cascader-menu-item ant-cascader-menu-item-disabled" role="menuitemcheckbox" aria-checked="false" data-path-key="Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__Xia Sha"><div class="ant-cascader-menu-item-content"><span class="ant-cascader-menu-item-keyword">Z</span>hejiang / Hang<span class="ant-cascader-menu-item-keyword">z</span>hou / Xia Sha</div></li></ul></div></div>"`;
exports[`Cascader > should highlight keyword and filter when search in Cascader with same field name of label and value 1`] = `"<div><div class=\\"ant-cascader-menus\\"><ul class=\\"ant-cascader-menu\\" role=\\"menu\\"><li class=\\"ant-cascader-menu-item\\" role=\\"menuitemcheckbox\\" aria-checked=\\"false\\" data-path-key=\\"Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__West Lake\\"><div class=\\"ant-cascader-menu-item-content\\"><span class=\\"ant-cascader-menu-item-keyword\\">Z</span>hejiang / Hang<span class=\\"ant-cascader-menu-item-keyword\\">z</span>hou / West Lake</div></li><li class=\\"ant-cascader-menu-item ant-cascader-menu-item-disabled\\" role=\\"menuitemcheckbox\\" aria-checked=\\"false\\" data-path-key=\\"Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__Xia Sha\\"><div class=\\"ant-cascader-menu-item-content\\"><span class=\\"ant-cascader-menu-item-keyword\\">Z</span>hejiang / Hang<span class=\\"ant-cascader-menu-item-keyword\\">z</span>hou / Xia Sha</div></li></ul></div></div>"`;
exports[`Cascader should render not found content 1`] = `
exports[`Cascader > should render not found content 1`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-empty ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: 0;"
@ -1743,7 +1743,7 @@ exports[`Cascader should render not found content 1`] = `
</div>
`;
exports[`Cascader should show not found content when options.length is 0 1`] = `
exports[`Cascader > should show not found content when options.length is 0 1`] = `
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up ant-cascader-dropdown ant-select-dropdown-empty ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: 0;"
@ -1818,7 +1818,7 @@ exports[`Cascader should show not found content when options.length is 0 1`] = `
</div>
`;
exports[`Cascader support controlled mode 1`] = `
exports[`Cascader > support controlled mode 1`] = `
<div
class="ant-select ant-cascader ant-select-single ant-select-allow-clear ant-select-show-arrow"
>

View File

@ -1,14 +1,14 @@
import React from 'react';
import type { SingleValueType } from 'rc-cascader/lib/Cascader';
import React from 'react';
import type { BaseOptionType, DefaultOptionType } from '..';
import Cascader from '..';
import excludeAllWarning from '../../../tests/shared/excludeWarning';
import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import ConfigProvider from '../../config-provider';
import { fireEvent, render } from '../../../tests/utils';
import { resetWarned } from '../../_util/warning';
import ConfigProvider from '../../config-provider';
const { SHOW_CHILD, SHOW_PARENT } = Cascader;
@ -90,7 +90,7 @@ describe('Cascader', () => {
});
it('popup correctly when panel is open', () => {
const onPopupVisibleChange = jest.fn();
const onPopupVisibleChange = vi.fn();
const { container } = render(
<Cascader options={options} onPopupVisibleChange={onPopupVisibleChange} />,
);
@ -123,7 +123,7 @@ describe('Cascader', () => {
});
it('can be selected', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(<Cascader open options={options} onChange={onChange} />);
clickOption(container, 0, 0);
@ -284,7 +284,7 @@ describe('Cascader', () => {
},
];
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Cascader
@ -320,7 +320,7 @@ describe('Cascader', () => {
});
describe('limit filtered item count', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
afterAll(() => {
errorSpy.mockRestore();
@ -353,9 +353,8 @@ describe('Cascader', () => {
});
// FIXME: Move to `rc-tree-select` instead
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should warning if not find `value` in `options`', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Cascader options={[{ label: 'a', value: 'a', children: [{ label: 'b' }] }]} />);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Cascader] Not found `value` in `options`.',
@ -410,8 +409,7 @@ describe('Cascader', () => {
const { container } = render(<Cascader options={customOptions} placement="topRight" />);
toggleOpen(container);
// Inject in tests/__mocks__/rc-trigger.js
expect((global as any)?.triggerProps.popupPlacement).toEqual('topRight');
expect(globalThis.triggerProps.popupPlacement).toEqual('topRight');
});
it('popup correctly with defaultValue RTL', () => {
@ -458,7 +456,7 @@ describe('Cascader', () => {
],
},
];
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<ConfigProvider direction="rtl">
<Cascader
@ -494,7 +492,7 @@ describe('Cascader', () => {
});
it('can be selected when showSearch', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(<Cascader options={options} onChange={onChange} showSearch />);
fireEvent.change(container.querySelector('input')!, { target: { value: 'Zh' } });
@ -514,7 +512,7 @@ describe('Cascader', () => {
});
it('onChange works correctly when the label of fieldNames is the same as value', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const sameNames = { label: 'label', value: 'label' };
const { container } = render(
<Cascader options={options} onChange={onChange} showSearch fieldNames={sameNames} />,
@ -528,21 +526,20 @@ describe('Cascader', () => {
const { container } = render(<Cascader options={options} direction="rtl" />);
toggleOpen(container);
// Inject in tests/__mocks__/rc-trigger.js
expect((global as any).triggerProps.popupPlacement).toEqual('bottomRight');
expect(globalThis.triggerProps.popupPlacement).toEqual('bottomRight');
});
describe('legacy props', () => {
it('popupPlacement', () => {
render(<Cascader open popupPlacement="bottomLeft" />);
// Inject in tests/__mocks__/rc-trigger.js
// Inject in __mocks__/@rc-component/trigger.tsx
expect((global as any).triggerProps.popupPlacement).toEqual('bottomLeft');
});
it('legacy dropdownClassName', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(<Cascader dropdownClassName="legacy" open />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: Cascader] `dropdownClassName` is deprecated. Please use `popupClassName` instead.',

View File

@ -335,7 +335,7 @@ if (process.env.NODE_ENV !== 'production') {
}
// We don't care debug panel
/* istanbul ignore next */
/* c8 ignore next */
const PurePanel = genPurePanel(Cascader);
Cascader.SHOW_PARENT = SHOW_PARENT;

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Checkbox rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`Checkbox > rtl render > component should be rendered correctly in RTL direction 1`] = `
<label
class="ant-checkbox-wrapper ant-checkbox-rtl"
>

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/checkbox/demo/basic.tsx extend context correctly 1`] = `
<label

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/checkbox/demo/basic.tsx correctly 1`] = `
<label

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`CheckboxGroup passes prefixCls down to checkbox 1`] = `
exports[`CheckboxGroup > passes prefixCls down to checkbox 1`] = `
<div
class="my-checkbox-group"
>
@ -46,7 +46,7 @@ exports[`CheckboxGroup passes prefixCls down to checkbox 1`] = `
</div>
`;
exports[`CheckboxGroup rtl render component should be rendered correctly in RTL direction 1`] = `
exports[`CheckboxGroup > rtl render > component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-checkbox-group ant-checkbox-group-rtl"
/>

View File

@ -12,8 +12,8 @@ describe('Checkbox', () => {
rtlTest(Checkbox);
it('responses hover events', () => {
const onMouseEnter = jest.fn();
const onMouseLeave = jest.fn();
const onMouseEnter = vi.fn();
const onMouseLeave = vi.fn();
const { container } = render(
<Checkbox onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />,
@ -29,7 +29,7 @@ describe('Checkbox', () => {
it('warning if set `value`', () => {
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<Checkbox value />);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Checkbox] `value` is not a valid prop, do you mean `checked`?',

View File

@ -14,7 +14,7 @@ describe('CheckboxGroup', () => {
rtlTest(Checkbox.Group);
it('should work basically', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group options={['Apple', 'Pear', 'Orange']} onChange={onChange} />,
);
@ -29,7 +29,7 @@ describe('CheckboxGroup', () => {
});
it('does not trigger onChange callback of both Checkbox and CheckboxGroup when CheckboxGroup is disabled', () => {
const onChangeGroup = jest.fn();
const onChangeGroup = vi.fn();
const options = [
{ label: 'Apple', value: 'Apple' },
@ -46,7 +46,7 @@ describe('CheckboxGroup', () => {
});
it('does not prevent onChange callback from Checkbox when CheckboxGroup is not disabled', () => {
const onChangeGroup = jest.fn();
const onChangeGroup = vi.fn();
const options = [
{ label: 'Apple', value: 'Apple' },
@ -94,7 +94,7 @@ describe('CheckboxGroup', () => {
// https://github.com/ant-design/ant-design/issues/12642
it('should trigger onChange in sub Checkbox', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group>
<Checkbox value="my" onChange={onChange} />
@ -107,7 +107,7 @@ describe('CheckboxGroup', () => {
// https://github.com/ant-design/ant-design/issues/16376
it('onChange should filter removed value', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container, rerender } = render(
<Checkbox.Group defaultValue={[1]} onChange={onChange}>
<Checkbox key={1} value={1} />
@ -126,7 +126,7 @@ describe('CheckboxGroup', () => {
});
it('checkbox should register value again after value changed', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container, rerender } = render(
<Checkbox.Group defaultValue={[1]} onChange={onChange}>
<Checkbox key={1} value={1} />
@ -144,7 +144,7 @@ describe('CheckboxGroup', () => {
// https://github.com/ant-design/ant-design/issues/17297
it('onChange should keep the order of the original values', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group onChange={onChange}>
<Checkbox key={1} value={1} />
@ -194,7 +194,7 @@ describe('CheckboxGroup', () => {
});
it('skipGroup', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group onChange={onChange}>
<Checkbox value={1} />
@ -206,7 +206,7 @@ describe('CheckboxGroup', () => {
});
it('Table rowSelection', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group onChange={onChange}>
<Table
@ -227,7 +227,7 @@ describe('CheckboxGroup', () => {
});
it('should support number option', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const { container } = render(
<Checkbox.Group options={[1, 'Pear', 'Orange']} onChange={onChange} />,
@ -238,7 +238,7 @@ describe('CheckboxGroup', () => {
});
it('should store latest checkbox value if changed', () => {
const onChange = jest.fn();
const onChange = vi.fn();
const Demo: React.FC = () => {
const [v, setV] = useState('');

View File

@ -1,4 +1,4 @@
// Compatible for babel-plugin-import
/* istanbul ignore next */
/* c8 ignore next */
export default {};

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/collapse/demo/accordion.tsx extend context correctly 1`] = `
<div
@ -1016,7 +1016,7 @@ Array [
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
style="max-height: 256px; overflow-y: auto; overflow-anchor: none;"
>
<div>
<div

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders components/collapse/demo/accordion.tsx correctly 1`] = `
<div

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Collapse Collapse.Panel usage 1`] = `
exports[`Collapse > Collapse.Panel usage 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start ant-collapse-borderless"
>
@ -87,7 +87,7 @@ exports[`Collapse Collapse.Panel usage 1`] = `
</div>
`;
exports[`Collapse could override default openMotion 1`] = `
exports[`Collapse > could override default openMotion 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start"
>
@ -144,7 +144,7 @@ exports[`Collapse could override default openMotion 1`] = `
</div>
`;
exports[`Collapse should render extra node of panel 1`] = `
exports[`Collapse > should render extra node of panel 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start"
>
@ -249,7 +249,7 @@ exports[`Collapse should render extra node of panel 1`] = `
</div>
`;
exports[`Collapse should support remove expandIcon 1`] = `
exports[`Collapse > should support remove expandIcon 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start"
>

View File

@ -1,19 +1,18 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { vi } from 'vitest';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import { resetWarned } from '../../_util/warning';
import Collapse from '../Collapse';
describe('Collapse', () => {
// eslint-disable-next-line global-require
const Collapse = require('..').default;
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
// fix React concurrent
function triggerAllTimer() {
for (let i = 0; i < 10; i += 1) {
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
}
}
@ -33,7 +32,7 @@ describe('Collapse', () => {
it('should support remove expandIcon', () => {
const { asFragment } = render(
<Collapse expandIcon={() => null}>
<Collapse.Panel header="header" />
<Collapse.Panel key={1} header="header" />
</Collapse>,
);
expect(asFragment().firstChild).toMatchSnapshot();
@ -56,7 +55,7 @@ describe('Collapse', () => {
</button>
)}
>
<Collapse.Panel header="header" />
<Collapse.Panel key={1} header="header" />
</Collapse>,
);
@ -66,15 +65,15 @@ describe('Collapse', () => {
it('should render extra node of panel', () => {
const { asFragment } = render(
<Collapse>
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
<Collapse.Panel header="header" key={1} extra={<button type="button">action</button>} />
<Collapse.Panel header="header" key={2} extra={<button type="button">action</button>} />
</Collapse>,
);
expect(asFragment().firstChild).toMatchSnapshot();
});
it('could be expand and collapse', async () => {
jest.useFakeTimers();
vi.useFakeTimers();
const { container } = render(
<Collapse>
<Collapse.Panel header="This is panel header 1" key="1">
@ -90,12 +89,13 @@ describe('Collapse', () => {
expect(
container.querySelector('.ant-collapse-item')?.classList.contains('ant-collapse-item-active'),
).toBe(true);
jest.useRealTimers();
vi.useRealTimers();
});
it('could override default openMotion', () => {
const props = { openMotion: {} };
const { container, asFragment } = render(
<Collapse openMotion={{}}>
<Collapse {...props}>
<Collapse.Panel header="This is panel header 1" key="1">
content
</Collapse.Panel>
@ -153,8 +153,8 @@ describe('Collapse', () => {
});
it('should end motion when set activeKey while hiding', async () => {
jest.useFakeTimers();
const spiedRAF = jest
vi.useFakeTimers();
const spiedRAF = vi
.spyOn(window, 'requestAnimationFrame')
.mockImplementation((cb) => setTimeout(cb, 16.66));
@ -185,7 +185,7 @@ describe('Collapse', () => {
expect(container.querySelectorAll('.ant-motion-collapse').length).toBe(0);
spiedRAF.mockRestore();
jest.useRealTimers();
vi.useRealTimers();
});
it('ref should work', () => {
@ -213,8 +213,7 @@ describe('Collapse', () => {
});
describe('expandIconPosition', () => {
['left', 'right'].forEach((pos) => {
it(`warning for legacy '${pos}'`, () => {
it.each(['left', 'right'] as const)(`warning for legacy %s'`, (pos) => {
render(
<Collapse expandIconPosition={pos}>
<Collapse.Panel header="header" key="1" />
@ -236,7 +235,6 @@ describe('Collapse', () => {
expect(container.querySelector('.ant-collapse-icon-position-end')).toBeTruthy();
});
});
});
it('Collapse.Panel usage', () => {
const { container } = render(

Some files were not shown because too many files have changed in this diff Show More