2017-08-24 12:56:25 +08:00
|
|
|
import React from 'react';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { mount } from 'enzyme';
|
2017-08-24 12:56:25 +08:00
|
|
|
import Checkbox from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2019-08-27 18:29:20 +08:00
|
|
|
import { resetWarned } from '../../_util/warning';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2017-08-24 12:56:25 +08:00
|
|
|
|
|
|
|
describe('Checkbox', () => {
|
2017-11-19 01:41:40 +08:00
|
|
|
focusTest(Checkbox);
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Checkbox);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Checkbox);
|
2017-11-19 01:41:40 +08:00
|
|
|
|
2017-08-24 12:56:25 +08:00
|
|
|
it('responses hover events', () => {
|
|
|
|
const onMouseEnter = jest.fn();
|
|
|
|
const onMouseLeave = jest.fn();
|
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Checkbox onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />);
|
2017-08-24 12:56:25 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
wrapper.find('label').simulate('mouseenter');
|
2017-08-24 12:56:25 +08:00
|
|
|
expect(onMouseEnter).toHaveBeenCalled();
|
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
wrapper.find('label').simulate('mouseleave');
|
2017-08-24 12:56:25 +08:00
|
|
|
expect(onMouseLeave).toHaveBeenCalled();
|
|
|
|
});
|
2019-08-27 18:29:20 +08:00
|
|
|
|
|
|
|
it('warning if set `value`', () => {
|
|
|
|
resetWarned();
|
|
|
|
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
mount(<Checkbox value />);
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2020-04-14 16:48:23 +08:00
|
|
|
'Warning: [antd: Checkbox] `value` is not a valid prop, do you mean `checked`?',
|
2019-08-27 18:29:20 +08:00
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2017-08-24 12:56:25 +08:00
|
|
|
});
|