2018-11-12 12:38:02 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2019-06-25 12:08:32 +08:00
|
|
|
import Switch from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2022-05-10 15:43:29 +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';
|
2021-11-26 12:18:21 +08:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2017-11-19 01:41:40 +08:00
|
|
|
|
|
|
|
describe('Switch', () => {
|
2020-04-26 22:33:36 +08:00
|
|
|
focusTest(Switch, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Switch);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Switch);
|
2018-11-12 12:38:02 +08:00
|
|
|
|
|
|
|
it('should has click wave effect', async () => {
|
|
|
|
const wrapper = mount(<Switch />);
|
2020-04-14 16:48:23 +08:00
|
|
|
wrapper.find('.ant-switch').getDOMNode().click();
|
2021-11-26 12:18:21 +08:00
|
|
|
await sleep(0);
|
2020-12-01 18:28:35 +08:00
|
|
|
expect(wrapper.find('button').getDOMNode().getAttribute('ant-click-animating')).toBe('true');
|
2018-11-12 12:38:02 +08:00
|
|
|
});
|
2019-08-27 18:29:20 +08:00
|
|
|
|
|
|
|
it('warning if set `value`', () => {
|
|
|
|
resetWarned();
|
|
|
|
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
mount(<Switch value />);
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2020-04-14 16:48:23 +08:00
|
|
|
'Warning: [antd: Switch] `value` is not a valid prop, do you mean `checked`?',
|
2019-08-27 18:29:20 +08:00
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2017-11-19 01:41:40 +08:00
|
|
|
});
|