@@ -8,7 +8,8 @@ import { html } from '../../test-utils/html'
8
8
import { click } from '../../test-utils/interactions'
9
9
import { getByText } from '../../test-utils/accessibility-assertions'
10
10
11
- function format ( input : Element | string ) {
11
+ function format ( input : Element | null | string ) {
12
+ if ( input === null ) throw new Error ( 'input is null' )
12
13
let contents = ( typeof input === 'string' ? input : ( input as HTMLElement ) . outerHTML ) . trim ( )
13
14
return prettier . format ( contents , { parser : 'babel' } )
14
15
}
@@ -22,32 +23,19 @@ beforeAll(() => {
22
23
23
24
afterAll ( ( ) => jest . restoreAllMocks ( ) )
24
25
25
- function renderTemplate ( input : string | Partial < Parameters < typeof defineComponent > [ 0 ] > ) {
26
- let defaultComponents = { Description }
27
-
28
- if ( typeof input === 'string' ) {
29
- return render ( defineComponent ( { template : input , components : defaultComponents } ) )
30
- }
31
-
32
- return render (
33
- defineComponent (
34
- Object . assign ( { } , input , {
35
- components : { ...defaultComponents , ...input . components } ,
36
- } ) as Parameters < typeof defineComponent > [ 0 ]
37
- )
38
- )
39
- }
40
-
41
26
it ( 'should be possible to use useDescriptions without using a Description' , async ( ) => {
42
- let { container } = renderTemplate ( {
43
- render ( ) {
44
- return h ( 'div' , [ h ( 'div' , { 'aria-describedby' : this . describedby } , [ 'No description' ] ) ] )
45
- } ,
46
- setup ( ) {
47
- let describedby = useDescriptions ( )
48
- return { describedby }
49
- } ,
50
- } )
27
+ let { container } = render (
28
+ defineComponent ( {
29
+ components : { Description } ,
30
+ render ( ) {
31
+ return h ( 'div' , [ h ( 'div' , { 'aria-describedby' : this . describedby } , [ 'No description' ] ) ] )
32
+ } ,
33
+ setup ( ) {
34
+ let describedby = useDescriptions ( )
35
+ return { describedby }
36
+ } ,
37
+ } )
38
+ )
51
39
52
40
expect ( format ( container . firstElementChild ) ) . toEqual (
53
41
format ( html `
@@ -59,20 +47,23 @@ it('should be possible to use useDescriptions without using a Description', asyn
59
47
} )
60
48
61
49
it ( 'should be possible to use useDescriptions and a single Description, and have them linked' , async ( ) => {
62
- let { container } = renderTemplate ( {
63
- render ( ) {
64
- return h ( 'div' , [
65
- h ( 'div' , { 'aria-describedby' : this . describedby } , [
66
- h ( Description , ( ) => 'I am a description' ) ,
67
- h ( 'span' , 'Contents' ) ,
68
- ] ) ,
69
- ] )
70
- } ,
71
- setup ( ) {
72
- let describedby = useDescriptions ( )
73
- return { describedby }
74
- } ,
75
- } )
50
+ let { container } = render (
51
+ defineComponent ( {
52
+ components : { Description } ,
53
+ render ( ) {
54
+ return h ( 'div' , [
55
+ h ( 'div' , { 'aria-describedby' : this . describedby } , [
56
+ h ( Description , ( ) => 'I am a description' ) ,
57
+ h ( 'span' , 'Contents' ) ,
58
+ ] ) ,
59
+ ] )
60
+ } ,
61
+ setup ( ) {
62
+ let describedby = useDescriptions ( )
63
+ return { describedby }
64
+ } ,
65
+ } )
66
+ )
76
67
77
68
await new Promise < void > ( nextTick )
78
69
@@ -89,21 +80,24 @@ it('should be possible to use useDescriptions and a single Description, and have
89
80
} )
90
81
91
82
it ( 'should be possible to use useDescriptions and multiple Description components, and have them linked' , async ( ) => {
92
- let { container } = renderTemplate ( {
93
- render ( ) {
94
- return h ( 'div' , [
95
- h ( 'div' , { 'aria-describedby' : this . describedby } , [
96
- h ( Description , ( ) => 'I am a description' ) ,
97
- h ( 'span' , 'Contents' ) ,
98
- h ( Description , ( ) => 'I am also a description' ) ,
99
- ] ) ,
100
- ] )
101
- } ,
102
- setup ( ) {
103
- let describedby = useDescriptions ( )
104
- return { describedby }
105
- } ,
106
- } )
83
+ let { container } = render (
84
+ defineComponent ( {
85
+ components : { Description } ,
86
+ render ( ) {
87
+ return h ( 'div' , [
88
+ h ( 'div' , { 'aria-describedby' : this . describedby } , [
89
+ h ( Description , ( ) => 'I am a description' ) ,
90
+ h ( 'span' , 'Contents' ) ,
91
+ h ( Description , ( ) => 'I am also a description' ) ,
92
+ ] ) ,
93
+ ] )
94
+ } ,
95
+ setup ( ) {
96
+ let describedby = useDescriptions ( )
97
+ return { describedby }
98
+ } ,
99
+ } )
100
+ )
107
101
108
102
await new Promise < void > ( nextTick )
109
103
@@ -121,21 +115,24 @@ it('should be possible to use useDescriptions and multiple Description component
121
115
} )
122
116
123
117
it ( 'should be possible to update a prop from the parent and it should reflect in the Description component' , async ( ) => {
124
- let { container } = renderTemplate ( {
125
- render ( ) {
126
- return h ( 'div' , [
127
- h ( 'div' , { 'aria-describedby' : this . describedby } , [
128
- h ( Description , ( ) => 'I am a description' ) ,
129
- h ( 'button' , { onClick : ( ) => this . count ++ } , '+1' ) ,
130
- ] ) ,
131
- ] )
132
- } ,
133
- setup ( ) {
134
- let count = ref ( 0 )
135
- let describedby = useDescriptions ( { props : { 'data-count' : count } } )
136
- return { count, describedby }
137
- } ,
138
- } )
118
+ let { container } = render (
119
+ defineComponent ( {
120
+ components : { Description } ,
121
+ render ( ) {
122
+ return h ( 'div' , [
123
+ h ( 'div' , { 'aria-describedby' : this . describedby } , [
124
+ h ( Description , ( ) => 'I am a description' ) ,
125
+ h ( 'button' , { onClick : ( ) => this . count ++ } , '+1' ) ,
126
+ ] ) ,
127
+ ] )
128
+ } ,
129
+ setup ( ) {
130
+ let count = ref ( 0 )
131
+ let describedby = useDescriptions ( { props : { 'data-count' : count } } )
132
+ return { count, describedby }
133
+ } ,
134
+ } )
135
+ )
139
136
140
137
await new Promise < void > ( nextTick )
141
138
0 commit comments