-
-
+
+
+ Manager
+
+
+
+ Engineer
+
+
- Engineer
+ yiminghe
-
+ class="rc-select-item-option-state-icon"
+ />
+
+
+
+ foo
+
+
-
- foo
-
-
- ✓
-
+ ✓
-
+
@@ -229,392 +203,9 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
`;
-exports[`Select.Tags max tag render not display maxTagPlaceholder if maxTagCount not reach 1`] = `
-
-`;
-
-exports[`Select.Tags max tag render truncates tags by maxTagCount and show maxTagPlaceholder 1`] = `
-
-
-
-
-
-
-
- One
-
-
-
- ×
-
-
-
-
-
-
-
- Two
-
-
-
- ×
-
-
-
-
-
-
-
-
- Omitted
-
-
-
-
-
-
-
-
-
-`;
-
-exports[`Select.Tags max tag render truncates tags by maxTagCount and show maxTagPlaceholder function 1`] = `
-
-
-
-
-
-
-
- One
-
-
-
- ×
-
-
-
-
-
-
-
- Two
-
-
-
- ×
-
-
-
-
-
-
-
-
- 1
- values omitted
-
-
-
-
-
-
-
-
-
-`;
-
exports[`Select.Tags max tag render truncates values by maxTagTextLength 1`] = `
-
-
-
-
-
-
-
- On...
-
-
-
- ×
-
-
-
-
-
-
-
- Tw...
-
-
-
- ×
-
-
-
-
-
-
-
-
-
+[
+ "On...",
+ "Tw...",
+]
`;
diff --git a/tests/__snapshots__/ssr.test.tsx.snap b/tests/__snapshots__/ssr.test.tsx.snap
index b66fe7ca8..412c3378c 100644
--- a/tests/__snapshots__/ssr.test.tsx.snap
+++ b/tests/__snapshots__/ssr.test.tsx.snap
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Select.SSR should work 1`] = `"
"`;
+exports[`Select.SSR should work 1`] = `"
"`;
diff --git a/tests/focus.test.tsx b/tests/focus.test.tsx
index c35c976d2..af042e147 100644
--- a/tests/focus.test.tsx
+++ b/tests/focus.test.tsx
@@ -66,23 +66,4 @@ describe('Select.Focus', () => {
jest.useRealTimers();
});
-
- it('IE focus', () => {
- jest.clearAllTimers();
- jest.useFakeTimers();
-
- jest.clearAllTimers();
-
- (document.body.style as any).msTouchAction = true;
- const { container } = render(
);
-
- const focusFn = jest.spyOn(container.querySelector('input'), 'focus');
-
- fireEvent.click(container.querySelector('.rc-select-selector'));
- jest.runAllTimers();
-
- expect(focusFn).toHaveBeenCalled();
-
- jest.useRealTimers();
- });
});
diff --git a/tests/placeholder.test.tsx b/tests/placeholder.test.tsx
index 9f6229d68..6853a5b5f 100644
--- a/tests/placeholder.test.tsx
+++ b/tests/placeholder.test.tsx
@@ -6,40 +6,38 @@ import { render } from '@testing-library/react';
describe('Select placeholder', () => {
it('when searchValue is controlled', () => {
const { container } = render(
);
- expect(container.querySelector('.rc-select-selection-placeholder')).not.toHaveStyle({
- visibility: 'hidden',
+ expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
+ visibility: 'visible',
});
toggleOpen(container);
- expect(container.querySelector('.rc-select-selection-placeholder')).toHaveStyle({
- visibility: 'hidden',
+ expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
+ visibility: 'visible',
});
});
it('when value is null', () => {
const { container } = render(
);
- expect(container.querySelector('.rc-select-selection-placeholder')).toBeTruthy();
- expect(container.querySelector('.rc-select-selection-placeholder').textContent).toBe('bamboo');
+ expect(container.querySelector('.rc-select-placeholder')).toBeTruthy();
+ expect(container.querySelector('.rc-select-placeholder').textContent).toBe('bamboo');
});
it('not when value is null but it is an Option', () => {
const { container } = render(
,
);
- expect(container.querySelector('.rc-select-selection-placeholder')).toBeFalsy();
- expect(container.querySelector('.rc-select-selection-item').textContent).toBe('light');
+ expect(container.querySelector('.rc-select-placeholder')).toBeFalsy();
+ expect(container.querySelector('.rc-select-content-value').textContent).toBe('light');
toggleOpen(container);
- expect(container.querySelector('.rc-select-selection-item').textContent).toBe('light');
+ expect(container.querySelector('.rc-select-content-value').textContent).toBe('light');
});
it('should hide placeholder if force closed and showSearch with searchValue', () => {
const { container } = render(
,
);
- expect(container.querySelector('.rc-select-selection-placeholder')).toHaveStyle({
+ expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
visibility: 'hidden',
});
- expect(container.querySelector('.rc-select-selection-placeholder').textContent).toBe(
- 'placeholder',
- );
+ expect(container.querySelector('.rc-select-placeholder').textContent).toBe('placeholder');
});
});
diff --git a/tests/setup.ts b/tests/setup.ts
new file mode 100644
index 000000000..1aba7af65
--- /dev/null
+++ b/tests/setup.ts
@@ -0,0 +1,28 @@
+window.MessageChannel = class {
+ port1: any;
+ port2: any;
+
+ constructor() {
+ const createPort = () => {
+ const port = {
+ onmessage: null,
+ postMessage: (message: any) => {
+ setTimeout(() => {
+ if (port._target && typeof port._target.onmessage === 'function') {
+ port._target.onmessage({ data: message });
+ }
+ }, 0);
+ },
+ _target: null,
+ };
+ return port;
+ };
+
+ const port1 = createPort();
+ const port2 = createPort();
+ port1._target = port2;
+ port2._target = port1;
+ this.port1 = port1;
+ this.port2 = port2;
+ }
+} as any;
diff --git a/tests/shared/allowClearTest.tsx b/tests/shared/allowClearTest.tsx
index e4903ee73..30cd2ba73 100644
--- a/tests/shared/allowClearTest.tsx
+++ b/tests/shared/allowClearTest.tsx
@@ -6,7 +6,7 @@ export default function allowClearTest(mode: any, value: any) {
describe('allowClear', () => {
it('renders correctly', () => {
const { container } = render(
);
- expect(container.querySelector('.rc-select-clear-icon')).toBeTruthy();
+ expect(container.querySelector('.rc-select-clear')).toBeTruthy();
});
it('clears value', () => {
const onClear = jest.fn();
diff --git a/tests/shared/blurTest.tsx b/tests/shared/blurTest.tsx
index 2ad391466..61c5503df 100644
--- a/tests/shared/blurTest.tsx
+++ b/tests/shared/blurTest.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import Option from '../../src/Option';
import Select from '../../src/Select';
import { injectRunAllTimers } from '../utils/common';
-import { type RenderResult, render, fireEvent, createEvent } from '@testing-library/react';
+import { type RenderResult, render, fireEvent, createEvent, act } from '@testing-library/react';
export default function blurTest(mode: any) {
describe(`blur of ${mode}`, () => {
@@ -34,8 +34,11 @@ export default function blurTest(mode: any) {
it('clears inputValue', () => {
fireEvent.change(wrapper.container.querySelector('input'), { target: { value: '1' } });
fireEvent.blur(wrapper.container.querySelector('input'));
+ act(() => {
+ jest.runAllTimers();
+ });
- expect(wrapper.container.querySelector('input').value).toBe('');
+ expect(wrapper.container.querySelector('input')).toHaveValue('');
});
it('blur()', () => {
@@ -62,11 +65,9 @@ export default function blurTest(mode: any) {
handleBlur.mockReset();
const preventDefault = jest.fn();
- const mouseDownEvent = createEvent.mouseDown(
- wrapper.container.querySelector('.rc-select-selector'),
- );
+ const mouseDownEvent = createEvent.mouseDown(wrapper.container.querySelector('.rc-select'));
mouseDownEvent.preventDefault = preventDefault;
- fireEvent(wrapper.container.querySelector('.rc-select-selector'), mouseDownEvent);
+ fireEvent(wrapper.container.querySelector('.rc-select'), mouseDownEvent);
expect(preventDefault).toHaveBeenCalled();
expect(handleBlur).not.toHaveBeenCalled();
diff --git a/tests/shared/inputFilterTest.tsx b/tests/shared/inputFilterTest.tsx
index a64f8a53c..f189f6099 100644
--- a/tests/shared/inputFilterTest.tsx
+++ b/tests/shared/inputFilterTest.tsx
@@ -1,10 +1,12 @@
import * as React from 'react';
import Option from '../../src/Option';
import Select from '../../src/Select';
-import { fireEvent, render } from '@testing-library/react';
+import { act, fireEvent, render } from '@testing-library/react';
export default function inputFilterTest(mode: any) {
it('should keep input filter after select when autoClearSearchValue is false', () => {
+ jest.useFakeTimers();
+
const { container } = render(
,
);
- expect(container.firstChild).toMatchSnapshot();
+ expect(
+ Array.from(container.querySelectorAll('.rc-select-selection-item-content')).map(
+ (ele) => ele.textContent,
+ ),
+ ).toMatchSnapshot();
});
it('truncates tags by maxTagCount', () => {
@@ -44,14 +48,15 @@ export default function maxTagTextLengthTest(mode: any) {
it('not display maxTagPlaceholder if maxTagCount not reach', () => {
const { container } = render(
-
,
);
- expect(container.firstChild).toMatchSnapshot();
+ expect(container.querySelectorAll('.rc-select-content-item')).toHaveLength(4);
+ expect(container.querySelector('.rc-select-content-item-rest')).toHaveTextContent('Omitted');
});
it('truncates tags by maxTagCount and show maxTagPlaceholder function', () => {
@@ -88,7 +94,10 @@ export default function maxTagTextLengthTest(mode: any) {
,
);
- expect(container.firstChild).toMatchSnapshot();
+ expect(container.querySelectorAll('.rc-select-content-item')).toHaveLength(4);
+ expect(container.querySelector('.rc-select-content-item-rest')).toHaveTextContent(
+ '1 values omitted',
+ );
});
it('tagRender should work on maxTagPlaceholder', () => {
diff --git a/tests/shared/removeSelectedTest.tsx b/tests/shared/removeSelectedTest.tsx
index aa997b699..fe4737e0f 100644
--- a/tests/shared/removeSelectedTest.tsx
+++ b/tests/shared/removeSelectedTest.tsx
@@ -42,7 +42,7 @@ export default function removeSelectedTest(mode: any) {
,
);
- expect(container.querySelector('.rc-select-selection-item-remove')).toBeFalsy();
+ expect(container.querySelector('.rc-select-item-remove')).toBeFalsy();
});
it('wrap value when labelInValue', () => {
diff --git a/tests/utils/common.ts b/tests/utils/common.ts
index affd0fc0f..d10ebe4cc 100644
--- a/tests/utils/common.ts
+++ b/tests/utils/common.ts
@@ -3,6 +3,9 @@ import { createEvent, fireEvent } from '@testing-library/react';
export function expectOpen(wrapper: any, open: boolean = true) {
if (wrapper instanceof HTMLElement) {
+ act(() => {
+ jest.runAllTimers();
+ });
expect(!!wrapper.querySelector('.rc-select-open')).toBe(open);
return;
}
@@ -18,15 +21,21 @@ export function expectOpen(wrapper: any, open: boolean = true) {
export function toggleOpen(wrapper: any) {
if (wrapper instanceof HTMLElement) {
- fireEvent.mouseDown(wrapper.querySelector('.rc-select-selector'));
+ fireEvent.mouseDown(wrapper.querySelector('.rc-select'));
+ act(() => {
+ jest.runAllTimers();
+ });
return;
}
- wrapper.find('.rc-select-selector').simulate('mousedown');
+ wrapper.find('.rc-select').simulate('mousedown');
}
export function selectItem(wrapper: any, index: number = 0) {
if (wrapper instanceof HTMLElement) {
fireEvent.click(wrapper.querySelectorAll('.rc-select-item-option-content')[index]);
+ act(() => {
+ jest.runAllTimers();
+ });
return;
}
wrapper.find('div.rc-select-item-option-content').at(index).simulate('click');
@@ -35,7 +44,9 @@ export function selectItem(wrapper: any, index: number = 0) {
export function findSelection(wrapper: any, index: number = 0) {
if (wrapper instanceof HTMLElement) {
const itemNode = wrapper.querySelectorAll('.rc-select-selection-item')[index];
- const contentNode = itemNode.querySelector('.rc-select-selection-item-content');
+ const contentNode =
+ itemNode?.querySelector('.rc-select-selection-item-content') ||
+ wrapper.querySelector('.rc-select-content-value');
if (contentNode) {
return contentNode;
@@ -43,8 +54,8 @@ export function findSelection(wrapper: any, index: number = 0) {
return itemNode;
} else {
- const itemNode = wrapper.find('.rc-select-selection-item').at(index);
- const contentNode = itemNode.find('.rc-select-selection-item-content');
+ const itemNode = wrapper.find('.rc-select-item').at(index);
+ const contentNode = itemNode.find('.rc-select-item-content');
if (contentNode.length) {
return contentNode;