|
1 | 1 | import { mount } from '@vue/test-utils'
|
2 | 2 | import { setConfig } from './config-set'
|
3 |
| -import { copyProps, makePropsConfigurable } from './props' |
| 3 | +import { copyProps, makeProp, makePropsConfigurable } from './props' |
4 | 4 |
|
5 | 5 | describe('utils/props', () => {
|
6 | 6 | it('copyProps() works with array props', async () => {
|
@@ -31,6 +31,49 @@ describe('utils/props', () => {
|
31 | 31 | expect(copyProps(props).c).toEqual(props.c)
|
32 | 32 | })
|
33 | 33 |
|
| 34 | + it('makeProp() works', async () => { |
| 35 | + expect(makeProp()).toEqual({}) |
| 36 | + expect(makeProp(undefined)).toEqual({}) |
| 37 | + expect(makeProp(null)).toEqual({}) |
| 38 | + expect(makeProp('')).toEqual({}) |
| 39 | + |
| 40 | + expect(makeProp(Array)).toEqual({ type: Array }) |
| 41 | + expect(makeProp(Boolean)).toEqual({ type: Boolean }) |
| 42 | + expect(makeProp(Function)).toEqual({ type: Function }) |
| 43 | + expect(makeProp(Number)).toEqual({ type: Number }) |
| 44 | + expect(makeProp(Object)).toEqual({ type: Object }) |
| 45 | + expect(makeProp(String)).toEqual({ type: String }) |
| 46 | + |
| 47 | + expect(makeProp(Array, null)).toEqual({ type: Array, default: null }) |
| 48 | + expect(makeProp(Boolean, false)).toEqual({ type: Boolean, default: false }) |
| 49 | + expect(makeProp(Function, null)).toEqual({ type: Function, default: null }) |
| 50 | + expect(makeProp(Number, 0)).toEqual({ type: Number, default: 0 }) |
| 51 | + expect(makeProp(Object, null)).toEqual({ type: Object, default: null }) |
| 52 | + expect(makeProp(String, '')).toEqual({ type: String, default: '' }) |
| 53 | + |
| 54 | + expect(typeof makeProp(Array, []).default).toEqual('function') |
| 55 | + expect(makeProp(Array, []).default()).toEqual([]) |
| 56 | + |
| 57 | + const fn = () => {} |
| 58 | + expect(typeof makeProp(Function, fn).default).toEqual('function') |
| 59 | + expect(makeProp(Function, fn).default).toEqual(fn) |
| 60 | + |
| 61 | + expect(typeof makeProp(Object, {}).default).toEqual('function') |
| 62 | + expect(makeProp(Object, {}).default()).toEqual({}) |
| 63 | + |
| 64 | + expect(makeProp(Array, true)).toEqual({ type: Array, required: true }) |
| 65 | + expect(makeProp(Boolean, true)).toEqual({ type: Boolean, default: true }) |
| 66 | + expect(makeProp(Function, true)).toEqual({ type: Function, required: true }) |
| 67 | + expect(makeProp(Number, true)).toEqual({ type: Number, required: true }) |
| 68 | + expect(makeProp(Object, true)).toEqual({ type: Object, required: true }) |
| 69 | + expect(makeProp(String, true)).toEqual({ type: String, required: true }) |
| 70 | + |
| 71 | + const validator = value => !!value |
| 72 | + expect(makeProp(String, '', undefined)).toEqual({ type: String, default: '' }) |
| 73 | + expect(makeProp(String, '', validator)).toEqual({ type: String, default: '', validator }) |
| 74 | + expect(makeProp(String, undefined, validator)).toEqual({ type: String, validator }) |
| 75 | + }) |
| 76 | + |
34 | 77 | it('makePropsConfigurable() works', async () => {
|
35 | 78 | const NAME = 'Component'
|
36 | 79 | const props = {
|
|
0 commit comments