@@ -96,3 +96,78 @@ test('byRole works without a global DOM', () => {
9696 </button>
9797 ` )
9898} )
99+
100+ test ( 'findBy works without a global DOM' , async ( ) => {
101+ const { window} = new JSDOM ( `<div>
102+ <div data-testid="test-id" aria-label="test-label">test text content</div>
103+ <select><option>display value</option></select>
104+ <input placeholder="placeholder" />
105+ <img alt="test alt text" src="/lucy-ricardo.png" />
106+ <span title="test title" />
107+ <div role="dialog"></div>
108+ <div role="meter progressbar"></div>
109+ <header>header</header>
110+ <input type="hidden" />
111+ </div>` )
112+
113+ await expect (
114+ dtl . findByLabelText ( window . document , 'test-label' ) ,
115+ ) . resolves . toBeTruthy ( )
116+ await expect (
117+ dtl . findAllByLabelText ( window . document , 'test-label' ) ,
118+ ) . resolves . toHaveLength ( 1 )
119+ await expect (
120+ dtl . findByPlaceholderText ( window . document , 'placeholder' ) ,
121+ ) . resolves . toBeTruthy ( )
122+ await expect (
123+ dtl . findAllByPlaceholderText ( window . document , 'placeholder' ) ,
124+ ) . resolves . toHaveLength ( 1 )
125+ await expect (
126+ dtl . findByText ( window . document , 'test text content' ) ,
127+ ) . resolves . toBeTruthy ( )
128+ await expect (
129+ dtl . findAllByText ( window . document , 'test text content' ) ,
130+ ) . resolves . toHaveLength ( 1 )
131+ await expect (
132+ dtl . findByAltText ( window . document , 'test alt text' ) ,
133+ ) . resolves . toBeTruthy ( )
134+ await expect (
135+ dtl . findAllByAltText ( window . document , 'test alt text' ) ,
136+ ) . resolves . toHaveLength ( 1 )
137+ await expect (
138+ dtl . findByTitle ( window . document , 'test title' ) ,
139+ ) . resolves . toBeTruthy ( )
140+ await expect (
141+ dtl . findAllByTitle ( window . document , 'test title' ) ,
142+ ) . resolves . toHaveLength ( 1 )
143+ await expect (
144+ dtl . findByDisplayValue ( window . document , 'display value' ) ,
145+ ) . resolves . toBeTruthy ( )
146+ await expect (
147+ dtl . findAllByDisplayValue ( window . document , 'display value' ) ,
148+ ) . resolves . toHaveLength ( 1 )
149+ await expect ( dtl . findByRole ( window . document , 'dialog' ) ) . resolves . toBeTruthy ( )
150+ await expect (
151+ dtl . findAllByRole ( window . document , 'dialog' ) ,
152+ ) . resolves . toHaveLength ( 1 )
153+ await expect ( dtl . findByRole ( window . document , 'meter' ) ) . resolves . toBeTruthy ( )
154+ await expect (
155+ dtl . findAllByRole ( window . document , 'meter' ) ,
156+ ) . resolves . toHaveLength ( 1 )
157+ await expect (
158+ dtl . findByRole ( window . document , 'progressbar' , { queryFallbacks : true } ) ,
159+ ) . resolves . toBeTruthy ( )
160+ await expect (
161+ dtl . findAllByRole ( window . document , 'progressbar' , { queryFallbacks : true } ) ,
162+ ) . resolves . toHaveLength ( 1 )
163+ await expect ( dtl . findByRole ( window . document , 'banner' ) ) . resolves . toBeTruthy ( )
164+ await expect (
165+ dtl . findAllByRole ( window . document , 'banner' ) ,
166+ ) . resolves . toHaveLength ( 1 )
167+ await expect (
168+ dtl . findByTestId ( window . document , 'test-id' ) ,
169+ ) . resolves . toBeTruthy ( )
170+ await expect (
171+ dtl . findAllByTestId ( window . document , 'test-id' ) ,
172+ ) . resolves . toHaveLength ( 1 )
173+ } )
0 commit comments