Skip to content

Commit 3dbdf4c

Browse files
committed
Add tests for coerce prop
1 parent e10b8b0 commit 3dbdf4c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('prop', function () {
295295

296296
describe('assertions', function () {
297297

298-
function makeInstance (value, type, validator) {
298+
function makeInstance (value, type, validator, coerce) {
299299
return new Vue({
300300
el: document.createElement('div'),
301301
template: '<test :test="val"></test>',
@@ -307,7 +307,8 @@ describe('prop', function () {
307307
props: {
308308
test: {
309309
type: type,
310-
validator: validator
310+
validator: validator,
311+
coerce: coerce
311312
}
312313
}
313314
}
@@ -391,6 +392,17 @@ describe('prop', function () {
391392
expect(hasWarned('Expected String')).toBe(true)
392393
})
393394

395+
it('type check + coerce', function () {
396+
makeInstance(123, String, null, String)
397+
expect(getWarnCount()).toBe(0)
398+
makeInstance('123', Number, null, Number)
399+
expect(getWarnCount()).toBe(0)
400+
makeInstance('123', Boolean, null, function (val) {
401+
return val === '123'
402+
})
403+
expect(getWarnCount()).toBe(0)
404+
})
405+
394406
it('required', function () {
395407
new Vue({
396408
el: document.createElement('div'),

0 commit comments

Comments
 (0)