test: add switch test
parent
68014c67d9
commit
ed2b541e87
|
@ -0,0 +1,3 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
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>`;
|
|
@ -1,6 +1,28 @@
|
||||||
import Switch from '..';
|
import Switch from '..';
|
||||||
|
import { mount } from '@vue/test-utils';
|
||||||
import focusTest from '../../../tests/shared/focusTest';
|
import focusTest from '../../../tests/shared/focusTest';
|
||||||
|
import { resetWarned } from '../../_util/warning';
|
||||||
|
import mountTest from '../../../tests/shared/mountTest';
|
||||||
|
|
||||||
describe('Switch', () => {
|
describe('Switch', () => {
|
||||||
focusTest(Switch);
|
focusTest(Switch);
|
||||||
|
mountTest(Switch);
|
||||||
|
|
||||||
|
it('should has click wave effect', async () => {
|
||||||
|
const wrapper = mount(Switch);
|
||||||
|
wrapper.find('.ant-switch').trigger('click');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 0));
|
||||||
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('warning if set `value`', () => {
|
||||||
|
resetWarned();
|
||||||
|
|
||||||
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
mount(Switch, { propsData: { value: '' } });
|
||||||
|
expect(errorSpy).toHaveBeenCalledWith(
|
||||||
|
'Warning: [antdv: Switch] `value` is not validate prop, do you mean `checked`?',
|
||||||
|
);
|
||||||
|
errorSpy.mockRestore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
|
import hasProp, { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
|
||||||
import VcSwitch from '../vc-switch';
|
import VcSwitch from '../vc-switch';
|
||||||
import Wave from '../_util/wave';
|
import Wave from '../_util/wave';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import Base from '../base';
|
import Base from '../base';
|
||||||
|
import warning from '../_util/warning';
|
||||||
|
|
||||||
const Switch = {
|
const Switch = {
|
||||||
name: 'ASwitch',
|
name: 'ASwitch',
|
||||||
|
__ANT_SWITCH: true,
|
||||||
model: {
|
model: {
|
||||||
prop: 'checked',
|
prop: 'checked',
|
||||||
event: 'change',
|
event: 'change',
|
||||||
|
@ -36,6 +38,13 @@ const Switch = {
|
||||||
this.$refs.refSwitchNode.blur();
|
this.$refs.refSwitchNode.blur();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
warning(
|
||||||
|
hasProp(this, 'checked') || !hasProp(this, 'value'),
|
||||||
|
'Switch',
|
||||||
|
'`value` is not validate prop, do you mean `checked`?',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(
|
const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(
|
||||||
|
|
Loading…
Reference in New Issue