1
- import expect from 'expect' ;
1
+ import test from 'tape' ;
2
+ import deepEqual from 'deep-equal-json' ;
3
+ import inspect from 'object-inspect' ;
4
+
2
5
import ariaPropsMap from '../../src/ariaPropsMap' ;
3
6
import rolesMap from '../../src/rolesMap' ;
4
7
@@ -56,20 +59,36 @@ const entriesList = [
56
59
[ 'aria-valuetext' , { 'type' : 'string' } ] ,
57
60
] ;
58
61
59
- describe ( 'ariaPropsMap API' , function ( ) {
60
- describe ( 'entries()' , function ( ) {
61
- test . each ( ariaPropsMap . entries ( ) ) ( 'Testing prop: %s' , ( obj , roles ) => {
62
- expect ( entriesList ) . toEqual (
63
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
64
- ) ;
62
+ test ( 'ariaPropsMap API' , async ( t ) => {
63
+ t . test ( 'iteration' , async ( st ) => {
64
+ st . notEqual ( ariaPropsMap [ Symbol . iterator ] , undefined , 'has an iterator defined' ) ;
65
+ st . equal ( [ ...ariaPropsMap ] . length , 51 , 'has a specific length' ) ;
66
+
67
+ st . test ( 'supports the spread operator' , async ( s2t ) => {
68
+ [ ...ariaPropsMap ] . forEach ( ( [ obj , roles ] ) => {
69
+ const found = entriesList . find ( ( [ o ] ) => deepEqual ( o , obj ) ) ;
70
+
71
+ s2t . ok ( found , `spread has element: ${ inspect ( obj ) } ` ) ;
72
+ s2t . deepEqual ( roles , found [ 1 ] , `for-of has object elements` ) ;
73
+ } ) ;
65
74
} ) ;
66
- test . each ( [ ...ariaPropsMap . entries ( ) ] ) ( 'Testing prop: %s' , ( obj , roles ) => {
67
- expect ( entriesList ) . toEqual (
68
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
69
- ) ;
75
+
76
+ st . test ( 'supports the for..of pattern' , async ( s2t ) => {
77
+ const output = [ ] ;
78
+ for ( const [ key , value ] of ariaPropsMap ) {
79
+ output . push ( [ key , value ] ) ;
80
+ }
81
+
82
+ output . forEach ( ( [ obj , roles ] ) => {
83
+ const found = entriesList . find ( ( [ o ] ) => deepEqual ( o , obj ) ) ;
84
+
85
+ s2t . ok ( found , `for-of has element: ${ inspect ( obj ) } ` ) ;
86
+ s2t . deepEqual ( roles , found [ 1 ] , `for-of has object elements` ) ;
87
+ } ) ;
70
88
} ) ;
71
89
} ) ;
72
- describe ( 'forEach()' , function ( ) {
90
+
91
+ t . test ( 'forEach()' , async ( st ) => {
73
92
const output = [ ] ;
74
93
let context ;
75
94
ariaPropsMap . forEach ( ( value , key , map ) => {
@@ -78,81 +97,48 @@ describe('ariaPropsMap API', function () {
78
97
context = map ;
79
98
}
80
99
} ) ;
81
- test . each ( output ) ( 'Testing prop: %s' , ( obj , roles ) => {
82
- expect ( entriesList ) . toEqual (
83
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
84
- ) ;
85
- } ) ;
86
- test . each ( context ) ( 'Testing prop: %s' , ( obj , roles ) => {
87
- expect ( entriesList ) . toEqual (
88
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
89
- ) ;
90
- } ) ;
100
+
101
+ for ( let i = 0 ; i < output . length ; i ++ ) {
102
+ const [ obj , roles ] = output [ i ] ;
103
+ const found = entriesList . find ( ( [ o ] ) => deepEqual ( o , obj ) ) ;
104
+
105
+ st . ok ( found , `\`forEach\` has element: ${ inspect ( obj ) } ` ) ;
106
+ st . deepEqual ( roles , found [ 1 ] , `\`forEach\` has object elements` ) ;
107
+ }
91
108
} ) ;
92
- it ( 'get()' , function ( ) {
93
- expect ( ariaPropsMap . get ( 'aria-label' ) ) . toBeDefined ( ) ;
94
- expect ( ariaPropsMap . get ( 'fake prop' ) ) . toBeUndefined ( ) ;
109
+
110
+ t . test ( 'get()' , async ( st ) => {
111
+ st . notEqual ( ariaPropsMap . get ( 'aria-label' ) , undefined , 'has a defined prop' )
112
+ st . equal ( ariaPropsMap . get ( 'fake prop' ) , undefined , 'returns undefined for a fake prop' ) ;
95
113
} ) ;
96
- it ( 'has()' , function ( ) {
97
- expect ( ariaPropsMap . has ( 'aria-label' ) ) . toEqual ( true ) ;
98
- expect ( ariaPropsMap . has ( 'fake prop' ) ) . toEqual ( false ) ;
114
+
115
+ t . test ( 'has()' , async ( st ) => {
116
+ st . equal ( ariaPropsMap . has ( 'aria-label' ) , true , 'has a defined prop' ) ;
117
+ st . equal ( ariaPropsMap . has ( 'fake prop' ) , false , 'returns false for a fake prop' ) ;
99
118
} ) ;
100
- describe ( 'keys()' , function ( ) {
119
+
120
+ t . test ( 'keys(), iteration' , async ( st ) => {
101
121
const entriesKeys = entriesList . map ( entry => entry [ 0 ] ) ;
102
- test . each ( ariaPropsMap . keys ( ) ) ( 'Testing key: %o' , ( key ) => {
103
- expect ( entriesKeys ) . toEqual (
104
- expect . arrayContaining ( [ key ] ) ,
105
- ) ;
106
- } ) ;
107
- test . each ( [ ...ariaPropsMap . keys ( ) ] ) ( 'Testing key: %o' , ( key ) => {
108
- expect ( entriesKeys ) . toEqual (
109
- expect . arrayContaining ( [ key ] ) ,
110
- ) ;
111
- } ) ;
112
- } ) ;
113
- describe ( 'values()' , function ( ) {
114
- const entriesValues = entriesList . map ( entry => entry [ 1 ] ) ;
115
- test . each ( ariaPropsMap . values ( ) ) ( 'Testing value: %o' , ( value ) => {
116
- expect ( entriesValues ) . toEqual (
117
- expect . arrayContaining ( [ value ] ) ,
118
- ) ;
119
- } ) ;
120
- test . each ( [ ...ariaPropsMap . values ( ) ] ) ( 'Testing value: %o' , ( value ) => {
121
- expect ( entriesValues ) . toEqual (
122
- expect . arrayContaining ( [ value ] ) ,
123
- ) ;
122
+ for ( const obj of ariaPropsMap . keys ( ) ) {
123
+ st . ok ( entriesKeys . find ( ( k ) => deepEqual ( k , obj ) ) , `for-of has key: ${ inspect ( obj ) } ` ) ;
124
+ }
125
+
126
+ [ ...ariaPropsMap . keys ( ) ] . forEach ( ( obj ) => {
127
+ st . ok ( entriesKeys . find ( ( k ) => deepEqual ( k , obj ) ) , `spread has key: ${ inspect ( obj ) } ` ) ;
124
128
} ) ;
125
129
} ) ;
126
- } ) ;
127
130
128
- describe ( 'ariaPropsMap' , function ( ) {
129
- describe ( 'iteration' , function ( ) {
130
- it ( 'should have an iterator defined' , function ( ) {
131
- expect ( ariaPropsMap [ Symbol . iterator ] ) . not . toBeUndefined ( ) ;
132
- } ) ;
133
- describe ( 'spread operator' , function ( ) {
134
- it ( 'should have a specific length' , function ( ) {
135
- expect ( ariaPropsMap . entries ( ) . length ) . toEqual ( 51 ) ;
136
- } ) ;
137
- test . each ( [ ...ariaPropsMap ] ) ( 'Testing prop: %s' , ( obj , roles ) => {
138
- expect ( entriesList ) . toEqual (
139
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
140
- ) ;
141
- } ) ;
142
- } ) ;
143
- describe ( 'for..of pattern' , function ( ) {
144
- const output = [ ] ;
145
- for ( const [ key , value ] of ariaPropsMap ) {
146
- output . push ( [ key , value ] ) ;
147
- }
148
- test . each ( output ) ( 'Testing prop: %s' , ( obj , roles ) => {
149
- expect ( entriesList ) . toEqual (
150
- expect . arrayContaining ( [ [ obj , roles ] ] ) ,
151
- ) ;
152
- } ) ;
131
+ t . test ( 'values(), iteration' , async ( st ) => {
132
+ for ( const values of ariaPropsMap . values ( ) ) {
133
+ st . ok ( entriesList . some ( ( [ , x ] ) => deepEqual ( x , values ) ) , `for-of has object values: ${ inspect ( values ) } ` ) ;
134
+ }
135
+
136
+ [ ...ariaPropsMap . values ( ) ] . forEach ( ( values ) => {
137
+ st . ok ( entriesList . some ( ( [ , x ] ) => deepEqual ( x , values ) ) , `spread has object values: ${ inspect ( values ) } ` ) ;
153
138
} ) ;
154
139
} ) ;
155
- describe ( 'props and role defintions' , function ( ) {
140
+
141
+ t . test ( 'props and role defintions' , async ( st ) => {
156
142
const usedProps = [ ] ;
157
143
for ( const roleDefinition of rolesMap . values ( ) ) {
158
144
for ( const prop of Object . keys ( roleDefinition . props ) ) {
@@ -168,11 +154,9 @@ describe('ariaPropsMap', function () {
168
154
}
169
155
}
170
156
}
171
- test . each ( ariaPropsMap . entries ( ) ) (
172
- 'The prop %s should be used in at least one role definition' ,
173
- ( prop ) => {
174
- expect ( usedProps . find ( p => p === prop ) ) . toBeDefined ( ) ;
175
- }
176
- ) ;
157
+
158
+ ariaPropsMap . forEach ( ( value , key ) => {
159
+ st . ok ( usedProps . find ( p => p === key ) , `has prop: ${ key } ` ) ;
160
+ } ) ;
177
161
} ) ;
178
162
} ) ;
0 commit comments