mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-11 23:00:20 +08:00
dbbf0dae75
* fix: InputNumber support null * test: update test case
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import InputNumber from '..';
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
|
|
describe('InputNumber', () => {
|
|
focusTest(InputNumber, { refFocus: true });
|
|
mountTest(InputNumber);
|
|
rtlTest(InputNumber);
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13896
|
|
it('should return null when blur a empty input number', () => {
|
|
const onChange = jest.fn();
|
|
const wrapper = mount(<InputNumber defaultValue="1" onChange={onChange} />);
|
|
wrapper.find('input').simulate('change', { target: { value: '' } });
|
|
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
});
|
|
|
|
it('should call onStep when press up or down button', () => {
|
|
const onStep = jest.fn();
|
|
const wrapper = mount(<InputNumber defaultValue={1} onStep={onStep} />);
|
|
wrapper.find('.ant-input-number-handler-up').simulate('mousedown');
|
|
expect(onStep).toBeCalledTimes(1);
|
|
expect(onStep).toHaveBeenLastCalledWith(2, { offset: 1, type: 'up' });
|
|
wrapper.find('.ant-input-number-handler-down').simulate('mousedown');
|
|
expect(onStep).toBeCalledTimes(2);
|
|
expect(onStep).toHaveBeenLastCalledWith(1, { offset: 1, type: 'down' });
|
|
});
|
|
});
|