|
| 1 | +import cases from 'jest-in-case' |
| 2 | +import {render} from './helpers/test-utils' |
| 3 | + |
| 4 | +cases( |
| 5 | + 'getBy* queries throw an error when there are multiple elements returned', |
| 6 | + ({name, query, html}) => { |
| 7 | + const utils = render(html) |
| 8 | + expect(() => utils[name](query)).toThrow(/multiple elements/i) |
| 9 | + }, |
| 10 | + { |
| 11 | + getByLabelText: { |
| 12 | + query: /his/, |
| 13 | + html: `<div aria-label="his"></div><div aria-label="history"></div>`, |
| 14 | + }, |
| 15 | + getByPlaceholderText: { |
| 16 | + query: /his/, |
| 17 | + html: `<input placeholder="his" /><input placeholder="history" />`, |
| 18 | + }, |
| 19 | + getByText: { |
| 20 | + query: /his/, |
| 21 | + html: `<div>his</div><div>history</div>`, |
| 22 | + }, |
| 23 | + getByAltText: { |
| 24 | + query: /his/, |
| 25 | + html: `<img alt="his" src="his.png" /><img alt="history" src="history.png" />`, |
| 26 | + }, |
| 27 | + getByTitle: { |
| 28 | + query: /his/, |
| 29 | + html: `<div title="his"></div><div title="history"></div>`, |
| 30 | + }, |
| 31 | + getByDisplayValue: { |
| 32 | + query: /his/, |
| 33 | + html: `<input value="his" /><select><option value="history">history</option></select>`, |
| 34 | + }, |
| 35 | + getByRole: { |
| 36 | + query: /his/, |
| 37 | + html: `<div role="his"></div><div role="history"></div>`, |
| 38 | + }, |
| 39 | + getByTestId: { |
| 40 | + query: /his/, |
| 41 | + html: `<div data-testid="his"></div><div data-testid="history"></div>`, |
| 42 | + }, |
| 43 | + }, |
| 44 | +) |
| 45 | + |
| 46 | +cases( |
| 47 | + 'queryBy* queries throw an error when there are multiple elements returned', |
| 48 | + ({name, query, html}) => { |
| 49 | + const utils = render(html) |
| 50 | + expect(() => utils[name](query)).toThrow(/multiple elements/i) |
| 51 | + }, |
| 52 | + { |
| 53 | + queryByLabelText: { |
| 54 | + query: /his/, |
| 55 | + html: `<div aria-label="his"></div><div aria-label="history"></div>`, |
| 56 | + }, |
| 57 | + queryByPlaceholderText: { |
| 58 | + query: /his/, |
| 59 | + html: `<input placeholder="his" /><input placeholder="history" />`, |
| 60 | + }, |
| 61 | + queryByText: { |
| 62 | + query: /his/, |
| 63 | + html: `<div>his</div><div>history</div>`, |
| 64 | + }, |
| 65 | + queryByAltText: { |
| 66 | + query: /his/, |
| 67 | + html: `<img alt="his" src="his.png" /><img alt="history" src="history.png" />`, |
| 68 | + }, |
| 69 | + queryByTitle: { |
| 70 | + query: /his/, |
| 71 | + html: `<div title="his"></div><div title="history"></div>`, |
| 72 | + }, |
| 73 | + queryByDisplayValue: { |
| 74 | + query: /his/, |
| 75 | + html: `<input value="his" /><select><option value="history">history</option></select>`, |
| 76 | + }, |
| 77 | + queryByRole: { |
| 78 | + query: /his/, |
| 79 | + html: `<div role="his"></div><div role="history"></div>`, |
| 80 | + }, |
| 81 | + queryByTestId: { |
| 82 | + query: /his/, |
| 83 | + html: `<div data-testid="his"></div><div data-testid="history"></div>`, |
| 84 | + }, |
| 85 | + }, |
| 86 | +) |
0 commit comments