Skip to content

Commit

Permalink
fix(element3): add change emit for switch
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Jan 1, 2021
1 parent e5fe4c8 commit 1c5d43f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/element3/src/components/Switch/src/Switch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default {
default: ''
}
},
emits: ['update:modelValue', 'update:change'],
emits: ['update:modelValue', 'change'],
setup(props, { emit }) {
const {
activeValue,
Expand Down Expand Up @@ -167,7 +167,7 @@ const useClick = ({
const newValue =
isChecked && isChecked.value ? inactiveValue.value : activeValue.value
emit('update:modelValue', newValue)
emit('update:change', newValue)
emit('change', newValue)
}
return {
Expand Down
11 changes: 11 additions & 0 deletions packages/element3/src/components/Switch/tests/Switch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,15 @@ describe('Switch', () => {

expect(wrapper.emitted('update:modelValue')).toEqual([['3']])
})

it('should emit change eventName when changed ', async () => {
const wrapper = mount(Switch, {
props: {
modelValue: false
}
})

await wrapper.trigger('click')
expect(wrapper.emitted('change')[0]).toEqual([true])
})
})

0 comments on commit 1c5d43f

Please sign in to comment.