mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
[improvement] Functional: ContactList, NavBar, Panel, SubmitBar, SwitchCell, Tag (#2675)
This commit is contained in:
@@ -5,34 +5,34 @@ import SwitchMixin from '../mixins/switch';
|
||||
|
||||
const [sfc, bem] = use('switch-cell');
|
||||
|
||||
export default sfc({
|
||||
mixins: [SwitchMixin],
|
||||
export default sfc(
|
||||
{
|
||||
mixins: [SwitchMixin],
|
||||
|
||||
props: {
|
||||
title: String,
|
||||
border: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
default: '24px'
|
||||
props: {
|
||||
title: String,
|
||||
border: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
default: '24px'
|
||||
}
|
||||
},
|
||||
|
||||
render(h, context) {
|
||||
const { props } = context;
|
||||
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
title={props.title}
|
||||
border={props.border}
|
||||
style={context.style}
|
||||
class={[bem(), context.class, context.staticClass]}
|
||||
>
|
||||
<Switch {...{ props, on: context.listeners }} />
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
value() {
|
||||
this.$emit('change', this.value);
|
||||
}
|
||||
},
|
||||
|
||||
render(h) {
|
||||
return (
|
||||
<Cell center title={this.title} border={this.border} class={bem()}>
|
||||
<Switch
|
||||
{...{ props: this.$props }}
|
||||
onInput={value => {
|
||||
this.$emit('input', value);
|
||||
}}
|
||||
/>
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
});
|
||||
true
|
||||
);
|
||||
|
@@ -1,13 +1,20 @@
|
||||
import SwitchCell from '..';
|
||||
import { mount } from '../../../test/utils';
|
||||
|
||||
test('emit event', () => {
|
||||
const wrapper = mount(SwitchCell);
|
||||
test('change event', () => {
|
||||
const onChange = jest.fn();
|
||||
const wrapper = mount(SwitchCell, {
|
||||
context: {
|
||||
on: {
|
||||
change: onChange
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.vm.$on('input', value => {
|
||||
wrapper.setProps({ value });
|
||||
});
|
||||
wrapper.find('.van-switch').trigger('click');
|
||||
|
||||
expect(wrapper.emitted('change')).toBeTruthy();
|
||||
expect(onChange.mock.calls[0]).toBeTruthy();
|
||||
});
|
||||
|
Reference in New Issue
Block a user