Browse Source

support short prop declaration as prop: true (#3643)

dev
Ivan Agafonov 8 years ago
committed by Evan You
parent
commit
b47d773c58
  1. 2
      src/core/util/props.js
  2. 13
      test/unit/features/options/props.spec.js

2
src/core/util/props.js

@ -91,7 +91,7 @@ function assertProp (
return return
} }
let type = prop.type let type = prop.type
let valid = !type let valid = !type || type === true
const expectedTypes = [] const expectedTypes = []
if (type) { if (type) {
if (!Array.isArray(type)) { if (!Array.isArray(type)) {

13
test/unit/features/options/props.spec.js

@ -244,6 +244,19 @@ describe('Options props', () => {
expect(console.error.calls.count()).toBe(2) expect(console.error.calls.count()).toBe(2)
expect('Expected Boolean').toHaveBeenWarned() expect('Expected Boolean').toHaveBeenWarned()
}) })
it('optional prop of any type (type: true or prop: true)', () => {
makeInstance(1, true)
expect(console.error.calls.count()).toBe(0)
makeInstance('any', true)
expect(console.error.calls.count()).toBe(0)
makeInstance({}, true)
expect(console.error.calls.count()).toBe(0)
makeInstance(undefined, true)
expect(console.error.calls.count()).toBe(0)
makeInstance(null, true)
expect(console.error.calls.count()).toBe(0)
})
}) })
it('should warn data fields already defined as a prop', () => { it('should warn data fields already defined as a prop', () => {

Loading…
Cancel
Save