From a4f7f5ae4de1b6538a0793c651a39fba9ae8b5d7 Mon Sep 17 00:00:00 2001 From: Natalia Tepluhina Date: Tue, 16 Apr 2019 22:31:16 +0300 Subject: [PATCH 1/6] feat: add test for checking native modifier --- test/unit/features/directives/on.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index a97ddaa8947..c88f82163b7 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -460,6 +460,20 @@ describe('Directive v-on', () => { expect(spy).toHaveBeenCalled() }) + it('should be able to ignore native modifier on native HTML element', () => { + vm = new Vue({ + el, + template: ` + + `, + methods: { foo: spy }, + }) + + triggerEvent(vm.$el, 'click') + expect(`You should not use the '.native' modifier on a native HTML element`).toHaveBeenWarned() + expect(spy.calls.count()).toBe(1) + }) + it('.once modifier should work with child components', () => { vm = new Vue({ el, From c4d33fa60569f4401545da0f3d0061c9700937dd Mon Sep 17 00:00:00 2001 From: Natalia Tepluhina Date: Wed, 17 Apr 2019 07:56:14 +0300 Subject: [PATCH 2/6] feat: add a warning on native modifier when used on elements --- src/core/vdom/create-element.js | 6 ++++++ test/unit/features/directives/on.spec.js | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index 46027084b51..8c92f502d64 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -98,6 +98,12 @@ export function _createElement ( ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag) if (config.isReservedTag(tag)) { // platform built-in elements + if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.nativeOn)) { + warn( + `The .native modifier for v-on is only valid on components.`, + context + ) + } vnode = new VNode( config.parsePlatformTagName(tag), data, children, undefined, undefined, context diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index c88f82163b7..5d617b8ef19 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -460,7 +460,7 @@ describe('Directive v-on', () => { expect(spy).toHaveBeenCalled() }) - it('should be able to ignore native modifier on native HTML element', () => { + it('should throw a warning is native modifier is used on native HTML element', () => { vm = new Vue({ el, template: ` @@ -470,8 +470,8 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(`You should not use the '.native' modifier on a native HTML element`).toHaveBeenWarned() - expect(spy.calls.count()).toBe(1) + expect(`The .native modifier for v-on is only valid on components.`).toHaveBeenWarned() + expect(spy.calls.count()).toBe(0) }) it('.once modifier should work with child components', () => { From ebc1283fadf6ec01fa66aa11c43be32ad67f9093 Mon Sep 17 00:00:00 2001 From: Natalia Tepluhina Date: Wed, 17 Apr 2019 08:39:04 +0300 Subject: [PATCH 3/6] fix: fixed a typo --- test/unit/features/directives/on.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index 5d617b8ef19..75c747f3b05 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -460,7 +460,7 @@ describe('Directive v-on', () => { expect(spy).toHaveBeenCalled() }) - it('should throw a warning is native modifier is used on native HTML element', () => { + it('should throw a warning if native modifier is used on native HTML element', () => { vm = new Vue({ el, template: ` From 4eb30822631b965e229702066f161f24395abde0 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 Apr 2019 11:41:12 +0300 Subject: [PATCH 4/6] Update src/core/vdom/create-element.js Co-Authored-By: NataliaTepluhina --- src/core/vdom/create-element.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index 8c92f502d64..ba36e15b12d 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -100,7 +100,7 @@ export function _createElement ( // platform built-in elements if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.nativeOn)) { warn( - `The .native modifier for v-on is only valid on components.`, + `The .native modifier for v-on is only valid on components but it was used on <${tag}>.`, context ) } From 109fae2ba571fc055e923f773f7814e869af1a63 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 Apr 2019 11:41:20 +0300 Subject: [PATCH 5/6] Update test/unit/features/directives/on.spec.js Co-Authored-By: NataliaTepluhina --- test/unit/features/directives/on.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index 75c747f3b05..d725ae78ecf 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -470,7 +470,7 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(`The .native modifier for v-on is only valid on components.`).toHaveBeenWarned() + expect(`The .native modifier for v-on is only valid on components but it was used on <${tag}>.`).toHaveBeenWarned() expect(spy.calls.count()).toBe(0) }) From 8aabed7ade04cfbe5b5e2c3584cf96def051dc24 Mon Sep 17 00:00:00 2001 From: Matthew Pietz Date: Fri, 19 Apr 2019 08:24:54 +0300 Subject: [PATCH 6/6] Update test/unit/features/directives/on.spec.js Co-Authored-By: NataliaTepluhina --- test/unit/features/directives/on.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index d725ae78ecf..b7801a82f22 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -470,7 +470,7 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(`The .native modifier for v-on is only valid on components but it was used on <${tag}>.`).toHaveBeenWarned() + expect(`The .native modifier for v-on is only valid on components but it was used on