|
| 1 | +import { describe, expect, test } from 'tstyche'; |
| 2 | +import type * as Vue2_6 from 'vue2-6/types/options'; |
| 3 | +import type * as Vue2_7 from 'vue2-7/types/options'; |
| 4 | +import type * as Vue3 from '@vue/runtime-core/dist/runtime-core'; |
| 5 | +import { dateProp } from '../../src/prop-types/date'; |
| 6 | +import { createVue2Component } from '../utils'; |
| 7 | +import type { Vue2ComponentWithProp } from '../utils'; |
| 8 | + |
| 9 | +describe('dateProp().optional', () => { |
| 10 | + test('Vue 2.6', () => { |
| 11 | + expect<Vue2_6.PropOptions<Date | undefined>>().type.toBeAssignableWith( |
| 12 | + dateProp().optional, |
| 13 | + ); |
| 14 | + expect<Vue2_6.PropOptions<Date>>().type.not.toBeAssignableWith( |
| 15 | + dateProp().optional, |
| 16 | + ); |
| 17 | + |
| 18 | + expect(createVue2Component(dateProp().optional)).type.toBe< |
| 19 | + Vue2ComponentWithProp<Date | undefined> |
| 20 | + >(); |
| 21 | + }); |
| 22 | + |
| 23 | + test('Vue 2.7', () => { |
| 24 | + expect<Vue2_7.PropOptions<Date | undefined>>().type.toBeAssignableWith( |
| 25 | + dateProp().optional, |
| 26 | + ); |
| 27 | + expect<Vue2_7.PropOptions<Date>>().type.not.toBeAssignableWith( |
| 28 | + dateProp().optional, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + test('Vue 3', () => { |
| 33 | + expect<Vue3.Prop<Date | undefined>>().type.toBeAssignableWith( |
| 34 | + dateProp().optional, |
| 35 | + ); |
| 36 | + expect<Vue3.Prop<Date>>().type.not.toBeAssignableWith(dateProp().optional); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('dateProp().nullable', () => { |
| 41 | + test('Vue 2.6', () => { |
| 42 | + expect<Vue2_6.PropOptions<Date | null>>().type.toBeAssignableWith( |
| 43 | + dateProp().nullable, |
| 44 | + ); |
| 45 | + expect<Vue2_6.PropOptions<Date>>().type.not.toBeAssignableWith( |
| 46 | + dateProp().nullable, |
| 47 | + ); |
| 48 | + |
| 49 | + expect(createVue2Component(dateProp().nullable)).type.toBe< |
| 50 | + Vue2ComponentWithProp<Date | null> |
| 51 | + >(); |
| 52 | + }); |
| 53 | + |
| 54 | + test('Vue 2.7', () => { |
| 55 | + expect<Vue2_7.PropOptions<Date | null>>().type.toBeAssignableWith( |
| 56 | + dateProp().nullable, |
| 57 | + ); |
| 58 | + expect<Vue2_7.PropOptions<Date>>().type.not.toBeAssignableWith( |
| 59 | + dateProp().nullable, |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + test('Vue 3', () => { |
| 64 | + expect<Vue3.Prop<Date | null>>().type.toBeAssignableWith( |
| 65 | + dateProp().nullable, |
| 66 | + ); |
| 67 | + expect<Vue3.Prop<Date>>().type.not.toBeAssignableWith(dateProp().nullable); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +describe('dateProp().withDefault(false)', () => { |
| 72 | + test('Vue 2.6', () => { |
| 73 | + expect<Vue2_6.PropOptions<Date>>().type.toBeAssignableWith( |
| 74 | + dateProp().withDefault(() => new Date()), |
| 75 | + ); |
| 76 | + expect<Vue2_6.PropOptions<string>>().type.not.toBeAssignableWith( |
| 77 | + dateProp().withDefault(() => new Date()), |
| 78 | + ); |
| 79 | + |
| 80 | + expect( |
| 81 | + createVue2Component(dateProp().withDefault(() => new Date())), |
| 82 | + ).type.toBe<Vue2ComponentWithProp<Date>>(); |
| 83 | + }); |
| 84 | + |
| 85 | + test('Vue 2.7', () => { |
| 86 | + expect<Vue2_7.PropOptions<Date>>().type.toBeAssignableWith( |
| 87 | + dateProp().withDefault(() => new Date()), |
| 88 | + ); |
| 89 | + expect<Vue2_7.PropOptions<string>>().type.not.toBeAssignableWith( |
| 90 | + dateProp().withDefault(() => new Date()), |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + test('Vue 3', () => { |
| 95 | + expect<Vue3.Prop<Date>>().type.toBeAssignableWith( |
| 96 | + dateProp().withDefault(() => new Date()), |
| 97 | + ); |
| 98 | + expect<Vue3.Prop<string>>().type.not.toBeAssignableWith( |
| 99 | + dateProp().withDefault(() => new Date()), |
| 100 | + ); |
| 101 | + }); |
| 102 | +}); |
| 103 | + |
| 104 | +describe('dateProp().required', () => { |
| 105 | + test('Vue 2.6', () => { |
| 106 | + expect<Vue2_6.PropOptions<Date>>().type.toBeAssignableWith( |
| 107 | + dateProp().required, |
| 108 | + ); |
| 109 | + expect<Vue2_6.PropOptions<string>>().type.not.toBeAssignableWith( |
| 110 | + dateProp().required, |
| 111 | + ); |
| 112 | + |
| 113 | + expect(createVue2Component(dateProp().required)).type.toBe< |
| 114 | + Vue2ComponentWithProp<Date> |
| 115 | + >(); |
| 116 | + }); |
| 117 | + |
| 118 | + test('Vue 2.7', () => { |
| 119 | + expect<Vue2_7.PropOptions<Date>>().type.toBeAssignableWith( |
| 120 | + dateProp().required, |
| 121 | + ); |
| 122 | + expect<Vue2_7.PropOptions<string>>().type.not.toBeAssignableWith( |
| 123 | + dateProp().required, |
| 124 | + ); |
| 125 | + }); |
| 126 | + |
| 127 | + test('Vue 3', () => { |
| 128 | + expect<Vue3.Prop<Date>>().type.toBeAssignableWith(dateProp().required); |
| 129 | + expect<Vue3.Prop<string>>().type.not.toBeAssignableWith( |
| 130 | + dateProp().required, |
| 131 | + ); |
| 132 | + }); |
| 133 | +}); |
0 commit comments