@@ -74,14 +74,28 @@ const valid = [
7474 `expect(await screen.findAllByRole("button")).not.toHaveLength(
7575 NUM_BUTTONS
7676 )` ,
77+ `expect( screen.getAllByRole("link") ).not.toHaveLength(0);` ,
78+
79+ `import {NUM_BUTTONS} from "./foo";
80+ expect(screen.getByText('foo')).toHaveLength(NUM_BUTTONS)` ,
81+ `expect(screen.getAllByText("foo")).toHaveLength(getLength())` ,
7782] ;
7883const invalid = [
79- // Invalid cases that applies to all variants
80-
8184 invalidCase (
8285 `expect(screen.getByText('foo')).toHaveLength(1)` ,
8386 `expect(screen.getByText('foo')).toBeInTheDocument()`
8487 ) ,
88+ invalidCase (
89+ `const NUM_BUTTONS=1;
90+ expect(screen.getByText('foo')).toHaveLength(NUM_BUTTONS)` ,
91+ `const NUM_BUTTONS=1;
92+ expect(screen.getByText('foo')).toBeInTheDocument()`
93+ ) ,
94+
95+ invalidCase (
96+ `expect(screen.queryAllByTestId("foo")).toHaveLength(0)` ,
97+ `expect(screen.queryByTestId("foo")).not.toBeInTheDocument()`
98+ ) ,
8599 invalidCase (
86100 `expect(getByText('foo')).toHaveLength(1)` ,
87101 `expect(getByText('foo')).toBeInTheDocument()`
@@ -205,54 +219,101 @@ const invalid = [
205219 ) ,
206220
207221 // Invalid cases that applies to queryBy* and queryAllBy*
208- ... [ "queryByText" , "queryAllByText" ] . map ( ( q ) => [
209- invalidCase (
210- `expect(${ q } ('foo')).toHaveLength(0)` ,
211- `expect(${ q } ('foo')).not.toBeInTheDocument()`
212- ) ,
213- invalidCase (
214- `expect(${ q } ('foo')).toBeNull()` ,
215- `expect(${ q } ('foo')).not.toBeInTheDocument()`
216- ) ,
217- invalidCase (
218- `expect(${ q } ('foo')).not.toBeNull()` ,
219- `expect(${ q } ('foo')).toBeInTheDocument()`
220- ) ,
221- invalidCase (
222- `expect(${ q } ('foo')) .not .toBeNull()` ,
223- `expect(${ q } ('foo')).toBeInTheDocument()`
224- ) ,
225- invalidCase (
226- `expect(${ q } ('foo')).toBeDefined()` ,
227- `expect(${ q } ('foo')).toBeInTheDocument()`
228- ) ,
229- invalidCase (
230- `expect(${ q } ('foo')) .not .toBeDefined()` ,
231- `expect(${ q } ('foo')) .not .toBeInTheDocument()`
232- ) ,
233- invalidCase (
234- `let foo;
235- foo = screen.${ q } ('foo');
222+
223+ invalidCase (
224+ `expect(queryByText ('foo')).toHaveLength(0)` ,
225+ `expect(queryByText ('foo')).not.toBeInTheDocument()`
226+ ) ,
227+ invalidCase (
228+ `expect(queryByText ('foo')).toBeNull()` ,
229+ `expect(queryByText ('foo')).not.toBeInTheDocument()`
230+ ) ,
231+ invalidCase (
232+ `expect(queryByText ('foo')).not.toBeNull()` ,
233+ `expect(queryByText ('foo')).toBeInTheDocument()`
234+ ) ,
235+ invalidCase (
236+ `expect(queryByText ('foo')) .not .toBeNull()` ,
237+ `expect(queryByText ('foo')).toBeInTheDocument()`
238+ ) ,
239+ invalidCase (
240+ `expect(queryByText ('foo')).toBeDefined()` ,
241+ `expect(queryByText ('foo')).toBeInTheDocument()`
242+ ) ,
243+ invalidCase (
244+ `expect(queryByText ('foo')) .not .toBeDefined()` ,
245+ `expect(queryByText ('foo')) .not .toBeInTheDocument()`
246+ ) ,
247+ invalidCase (
248+ `let foo;
249+ foo = screen.queryByText ('foo');
236250 expect(foo).toHaveLength(0);` ,
237- `let foo;
238- foo = screen.${ q } ('foo');
251+ `let foo;
252+ foo = screen.queryByText ('foo');
239253 expect(foo).not.toBeInTheDocument();`
240- ) ,
241- invalidCase (
242- `let foo;
243- foo = screen.${ q } ('foo');
254+ ) ,
255+ invalidCase (
256+ `let foo;
257+ foo = screen.queryByText ('foo');
244258 expect(foo) .not.toBeNull();` ,
245- `let foo;
246- foo = screen.${ q } ('foo');
259+ `let foo;
260+ foo = screen.queryByText('foo');
261+ expect(foo).toBeInTheDocument();`
262+ ) ,
263+ invalidCase (
264+ `let foo = screen.queryByText('foo');
265+ expect(foo).not.toBeNull();` ,
266+ `let foo = screen.queryByText('foo');
267+ expect(foo).toBeInTheDocument();`
268+ ) ,
269+
270+ invalidCase (
271+ `expect(queryAllByText('foo')).toHaveLength(0)` ,
272+ `expect(queryByText('foo')).not.toBeInTheDocument()`
273+ ) ,
274+ invalidCase (
275+ `expect(queryAllByText('foo')).toBeNull()` ,
276+ `expect(queryByText('foo')).not.toBeInTheDocument()`
277+ ) ,
278+ invalidCase (
279+ `expect(queryAllByText('foo')).not.toBeNull()` ,
280+ `expect(queryByText('foo')).toBeInTheDocument()`
281+ ) ,
282+ invalidCase (
283+ `expect(queryAllByText('foo')) .not .toBeNull()` ,
284+ `expect(queryByText('foo')).toBeInTheDocument()`
285+ ) ,
286+ invalidCase (
287+ `expect(queryAllByText('foo')).toBeDefined()` ,
288+ `expect(queryByText('foo')).toBeInTheDocument()`
289+ ) ,
290+ invalidCase (
291+ `expect(queryAllByText('foo')) .not .toBeDefined()` ,
292+ `expect(queryByText('foo')) .not .toBeInTheDocument()`
293+ ) ,
294+ invalidCase (
295+ `let foo;
296+ foo = screen.queryAllByText('foo');
297+ expect(foo).toHaveLength(0);` ,
298+ `let foo;
299+ foo = screen.queryByText('foo');
300+ expect(foo).not.toBeInTheDocument();`
301+ ) ,
302+ invalidCase (
303+ `let foo;
304+ foo = screen.queryAllByText('foo');
305+ expect(foo) .not.toBeNull();` ,
306+ `let foo;
307+ foo = screen.queryByText('foo');
247308 expect(foo).toBeInTheDocument();`
248- ) ,
249- invalidCase (
250- `let foo = screen.${ q } ('foo');
309+ ) ,
310+ invalidCase (
311+ `let foo = screen.queryAllByText ('foo');
251312 expect(foo).not.toBeNull();` ,
252- `let foo = screen.${ q } ('foo');
313+ `let foo = screen.queryByText ('foo');
253314 expect(foo).toBeInTheDocument();`
254- ) ,
255- ] ) ,
315+ ) ,
316+ //END
256317 invalidCase (
257318 `it("foo", async () => {
258319 expect(await findByRole("button")).toBeDefined();
0 commit comments