Skip to content

Commit

Permalink
feat: modify some test cases caused by null value.
Browse files Browse the repository at this point in the history
  • Loading branch information
shezhangzhang committed Jun 13, 2022
1 parent 206b49f commit 007c0f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
32 changes: 18 additions & 14 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { mount, render } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { resetWarned } from 'rc-util/lib/warning';
import type { ScrollConfig } from 'rc-virtual-list/lib/List';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import { resetWarned } from 'rc-util/lib/warning';
import VirtualList from 'rc-virtual-list';
import type { ScrollConfig } from 'rc-virtual-list/lib/List';
import React from 'react';
import { act } from 'react-dom/test-utils';
import type { SelectProps } from '../src';
import Select, { OptGroup, Option, useBaseProps } from '../src';
import focusTest from './shared/focusTest';
import type { BaseSelectRef } from '../src/BaseSelect';
import allowClearTest from './shared/allowClearTest';
import blurTest from './shared/blurTest';
import keyDownTest from './shared/keyDownTest';
import focusTest from './shared/focusTest';
import inputFilterTest from './shared/inputFilterTest';
import keyDownTest from './shared/keyDownTest';
import openControlledTest from './shared/openControlledTest';
import allowClearTest from './shared/allowClearTest';
import {
expectOpen,
toggleOpen,
selectItem,
findSelection,
injectRunAllTimers,
selectItem,
toggleOpen,
} from './utils/common';
import type { BaseSelectRef } from '../src/BaseSelect';

describe('Select.Basic', () => {
injectRunAllTimers(jest);
Expand Down Expand Up @@ -1646,7 +1646,7 @@ describe('Select.Basic', () => {
});
});

it('`null` is a value', () => {
it('`null` can not be a value', () => {
const onChange = jest.fn();

const wrapper = mount(
Expand All @@ -1666,8 +1666,12 @@ describe('Select.Basic', () => {
].forEach(([value, showValue], index) => {
toggleOpen(wrapper);
selectItem(wrapper, index);
expect(onChange).toHaveBeenCalledWith(value, expect.anything());
expect(wrapper.find('.rc-select-selection-item').text()).toEqual(showValue);
expect(onChange).toHaveBeenCalledWith(value, value === null ? null : expect.anything());
if (value === null) {
expect(wrapper.find('.rc-select-selection-item').length).toBeFalsy();
} else {
expect(wrapper.find('.rc-select-selection-item').text()).toEqual(showValue);
}
});
});

Expand All @@ -1693,7 +1697,7 @@ describe('Select.Basic', () => {
const wrapper = mount(
<Select value={null} placeholder="bamboo" options={[{ value: null, label: 'light' }]} />,
);
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy();
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeTruthy();
});
});

Expand Down
10 changes: 3 additions & 7 deletions tests/shared/allowClearTest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, mount } from 'enzyme';
import * as React from 'react';
import { mount, render } from 'enzyme';
import Select, { Option } from '../../src';

export default function allowClearTest(mode: any, value: any) {
Expand Down Expand Up @@ -31,14 +30,11 @@ export default function allowClearTest(mode: any, value: any) {

// enabled
wrapper.setProps({ disabled: false });
wrapper
.find('.rc-select-clear')
.last()
.simulate('mousedown');
wrapper.find('.rc-select-clear').last().simulate('mousedown');
if (useArrayValue) {
expect(onChange).toHaveBeenCalledWith([], []);
} else {
expect(onChange).toHaveBeenCalledWith(undefined, undefined);
expect(onChange).toHaveBeenCalledWith(null, null);
}
expect(wrapper.find('input').props().value).toEqual('');
expect(onClear).toHaveBeenCalled();
Expand Down

0 comments on commit 007c0f0

Please sign in to comment.