feat(directives): introduce created custom directive hook and ensure

`v-model` event listener fire before template/props listeners

fix #1931
This commit is contained in:
Evan You
2020-08-24 17:12:16 -04:00
parent 016ba116a8
commit 11804fe93f
4 changed files with 28 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ beforeEach(() => {
describe('vModel', () => {
it('should work with text input', async () => {
const manualListener = jest.fn()
const component = defineComponent({
data() {
return { value: null }
@@ -37,7 +38,10 @@ describe('vModel', () => {
return [
withVModel(
h('input', {
'onUpdate:modelValue': setValue.bind(this)
'onUpdate:modelValue': setValue.bind(this),
onInput: () => {
manualListener(data.value)
}
}),
this.value
)
@@ -54,6 +58,8 @@ describe('vModel', () => {
triggerEvent('input', input)
await nextTick()
expect(data.value).toEqual('foo')
// #1931
expect(manualListener).toHaveBeenCalledWith('foo')
data.value = 'bar'
await nextTick()