Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c04cde

Browse filesBrowse files
committed
do not warn for absent non-required prop (close vuejs#1070)
1 parent 7b6913e commit 3c04cde
Copy full SHA for 3c04cde

File tree

Expand file treeCollapse file tree

2 files changed

+28
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-5
lines changed

‎src/util/component.js

Copy file name to clipboardExpand all lines: src/util/component.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ exports.initProp = function (vm, prop, value) {
5959
*/
6060

6161
exports.assertProp = function (prop, value) {
62+
// if a prop is not provided and is not required,
63+
// skip the check.
64+
if (prop.raw === null && !prop.required) {
65+
return true
66+
}
6267
var options = prop.options
6368
var type = options.type
6469
var valid = true

‎test/unit/specs/directives/prop_spec.js

Copy file name to clipboardExpand all lines: test/unit/specs/directives/prop_spec.js
+23-5Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ if (_.inBrowser) {
447447
}))
448448
})
449449

450-
it('should initialize with default value when not provided & has default data', function () {
450+
it('should initialize with default value when not provided & has default data', function (done) {
451451
var vm = new Vue({
452452
el: el,
453453
template: '<test></test>',
@@ -469,10 +469,28 @@ if (_.inBrowser) {
469469
}
470470
})
471471
expect(vm.$el.textContent).toBe('hello world')
472-
expect(JSON.stringify(vm.$children[0].$data)).toBe(JSON.stringify({
473-
other: 'world',
474-
prop: 'hello'
475-
}))
472+
vm.$children[0].prop = 'bye'
473+
_.nextTick(function () {
474+
expect(vm.$el.textContent).toBe('bye world')
475+
done()
476+
})
477+
})
478+
479+
it('should not warn for non-required, absent prop', function () {
480+
new Vue({
481+
el: el,
482+
template: '<test></test>',
483+
components: {
484+
test: {
485+
props: {
486+
prop: {
487+
type: String
488+
}
489+
}
490+
}
491+
}
492+
})
493+
expect(_.warn).not.toHaveBeenCalled()
476494
})
477495
})
478496
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.