@@ -9,6 +9,7 @@ describe('DOM test utils', () => {
99 let node : HTMLElement , wrapper : ElementWrapper ;
1010
1111 const CLASS_NAME = 'some-class' ;
12+ const BUTTON_CLASS_NAME = 'some-class-button' ;
1213
1314 const LIST_WITH_ITEMS_CLASS_NAME = 'list-with-items' ;
1415 const LIST_WITHOUT_ITEMS_CLASS_NAME = 'list-without-items' ;
@@ -26,11 +27,12 @@ describe('DOM test utils', () => {
2627 <a>2</a>
2728 <a>2</a>
2829 </div>
29- <button class="${ CLASS_NAME } active">1</button>
30- <button class="${ CLASS_NAME } ">1</button>
30+ <button class="${ BUTTON_CLASS_NAME } ${ CLASS_NAME } active">1</button>
31+ <button class="${ BUTTON_CLASS_NAME } ${ CLASS_NAME } ">1</button>
3132 <div>
32- <button>2</button>
33- <button>2</button>
33+ <button class="${ BUTTON_CLASS_NAME } ">2</button>
34+ <button class="${ BUTTON_CLASS_NAME } ">2</button>
35+ <button class="${ BUTTON_CLASS_NAME } ">12</button>
3436 </div>
3537 <div class="second-type">should not match</div>
3638 <ul class="${ LIST_WITH_ITEMS_CLASS_NAME } ">
@@ -241,6 +243,9 @@ describe('DOM test utils', () => {
241243 class ListItemWrapper extends ComponentWrapper < HTMLUListElement > {
242244 static rootSelector = LIST_ITEM_CLASS_NAME ;
243245 }
246+ class ButtonWrapper extends ComponentWrapper < HTMLButtonElement > {
247+ static rootSelector = BUTTON_CLASS_NAME ;
248+ }
244249
245250 it ( 'returns an array of all components matching the wrapper class' , ( ) => {
246251 const nodeWithListItemComponents = node . querySelector ( `.${ LIST_WITH_ITEMS_CLASS_NAME } ` ) ! ;
@@ -267,6 +272,32 @@ describe('DOM test utils', () => {
267272
268273 expect ( listItems ) . toHaveLength ( 0 ) ;
269274 } ) ;
275+
276+ describe ( 'AOM querying' , ( ) => {
277+ describe ( 'name' , ( ) => {
278+ it ( 'should filter based on accessible name: exact string match' , ( ) => {
279+ const wrapper = createWrapper ( node ) ;
280+ const buttons = wrapper . findAllComponents ( ButtonWrapper , { name : '1' } ) ;
281+ const buttonsContent = buttons . map ( wrapper => wrapper . getElement ( ) . textContent ) ;
282+
283+ expect ( buttonsContent ) . toEqual ( [ '1' , '1' ] ) ;
284+ } ) ;
285+ it ( 'should filter based on accessible name: loose match with regex' , ( ) => {
286+ const wrapper = createWrapper ( node ) ;
287+ const buttons = wrapper . findAllComponents ( ButtonWrapper , { name : / 1 / } ) ;
288+ const buttonsContent = buttons . map ( wrapper => wrapper . getElement ( ) . textContent ) ;
289+
290+ expect ( buttonsContent ) . toEqual ( [ '1' , '1' , '12' ] ) ;
291+ } ) ;
292+ it ( 'should filter based on accessible name: function' , ( ) => {
293+ const wrapper = createWrapper ( node ) ;
294+ const buttons = wrapper . findAllComponents ( ButtonWrapper , { name : name => name === '12' } ) ;
295+ const buttonsContent = buttons . map ( wrapper => wrapper . getElement ( ) . textContent ) ;
296+
297+ expect ( buttonsContent ) . toEqual ( [ '12' ] ) ;
298+ } ) ;
299+ } ) ;
300+ } ) ;
270301 } ) ;
271302 } ) ;
272303
0 commit comments