mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[improvement] Switch: functional (#2736)
This commit is contained in:
@@ -2,12 +2,39 @@ import Switch from '..';
|
||||
import { mount } from '../../../test/utils';
|
||||
|
||||
test('emit event', () => {
|
||||
const wrapper = mount(Switch);
|
||||
const input = jest.fn();
|
||||
const change = jest.fn();
|
||||
const wrapper = mount(Switch, {
|
||||
context: {
|
||||
on: {
|
||||
input,
|
||||
change
|
||||
}
|
||||
}
|
||||
});
|
||||
wrapper.trigger('click');
|
||||
wrapper.trigger('click');
|
||||
wrapper.setProps({ disabled: true });
|
||||
wrapper.trigger('click');
|
||||
|
||||
expect(wrapper.emitted('input')).toEqual([[true], [true]]);
|
||||
expect(wrapper.emitted('change')).toEqual([[true], [true]]);
|
||||
expect(input.mock.calls).toEqual([[true], [true]]);
|
||||
expect(change.mock.calls).toEqual([[true], [true]]);
|
||||
});
|
||||
|
||||
test('disabled', () => {
|
||||
const input = jest.fn();
|
||||
const change = jest.fn();
|
||||
const wrapper = mount(Switch, {
|
||||
context: {
|
||||
on: {
|
||||
input,
|
||||
change
|
||||
}
|
||||
},
|
||||
propsData: {
|
||||
disabled: true
|
||||
}
|
||||
});
|
||||
wrapper.trigger('click');
|
||||
|
||||
expect(input.mock.calls.length).toBeFalsy();
|
||||
expect(change.mock.calls.length).toBeFalsy();
|
||||
});
|
||||
|
Reference in New Issue
Block a user