Skip to content

Commit ed2b541

Browse files
committed
test: add switch test
1 parent 68014c6 commit ed2b541

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Switch should has click wave effect 1`] = `<button type="button" role="switch" class="ant-switch ant-switch-checked" aria-checked="true"><span class="ant-switch-inner"></span></button>`;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import Switch from '..';
2+
import { mount } from '@vue/test-utils';
23
import focusTest from '../../../tests/shared/focusTest';
4+
import { resetWarned } from '../../_util/warning';
5+
import mountTest from '../../../tests/shared/mountTest';
36

47
describe('Switch', () => {
58
focusTest(Switch);
9+
mountTest(Switch);
10+
11+
it('should has click wave effect', async () => {
12+
const wrapper = mount(Switch);
13+
wrapper.find('.ant-switch').trigger('click');
14+
await new Promise(resolve => setTimeout(resolve, 0));
15+
expect(wrapper.html()).toMatchSnapshot();
16+
});
17+
18+
it('warning if set `value`', () => {
19+
resetWarned();
20+
21+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
22+
mount(Switch, { propsData: { value: '' } });
23+
expect(errorSpy).toHaveBeenCalledWith(
24+
'Warning: [antdv: Switch] `value` is not validate prop, do you mean `checked`?',
25+
);
26+
errorSpy.mockRestore();
27+
});
628
});

components/switch/index.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import PropTypes from '../_util/vue-types';
2-
import { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
2+
import hasProp, { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
33
import VcSwitch from '../vc-switch';
44
import Wave from '../_util/wave';
55
import Icon from '../icon';
66
import { ConfigConsumerProps } from '../config-provider';
77
import Base from '../base';
8+
import warning from '../_util/warning';
89

910
const Switch = {
1011
name: 'ASwitch',
12+
__ANT_SWITCH: true,
1113
model: {
1214
prop: 'checked',
1315
event: 'change',
@@ -36,6 +38,13 @@ const Switch = {
3638
this.$refs.refSwitchNode.blur();
3739
},
3840
},
41+
created() {
42+
warning(
43+
hasProp(this, 'checked') || !hasProp(this, 'value'),
44+
'Switch',
45+
'`value` is not validate prop, do you mean `checked`?',
46+
);
47+
},
3948

4049
render() {
4150
const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(

0 commit comments

Comments
 (0)