|
| 1 | +import { |
| 2 | + getByLabelText, |
| 3 | + getAllByLabelText, |
| 4 | + queryAllByLabelText, |
| 5 | + queryByLabelText, |
| 6 | + findByLabelText, |
| 7 | + findAllByLabelText, |
| 8 | + getByPlaceholderText, |
| 9 | + getAllByPlaceholderText, |
| 10 | + queryAllByPlaceholderText, |
| 11 | + queryByPlaceholderText, |
| 12 | + findByPlaceholderText, |
| 13 | + findAllByPlaceholderText, |
| 14 | + getByText, |
| 15 | + getAllByText, |
| 16 | + queryAllByText, |
| 17 | + queryByText, |
| 18 | + findByText, |
| 19 | + findAllByText, |
| 20 | + getByAltText, |
| 21 | + getAllByAltText, |
| 22 | + queryAllByAltText, |
| 23 | + queryByAltText, |
| 24 | + findByAltText, |
| 25 | + findAllByAltText, |
| 26 | + getByTitle, |
| 27 | + getAllByTitle, |
| 28 | + queryAllByTitle, |
| 29 | + queryByTitle, |
| 30 | + findByTitle, |
| 31 | + findAllByTitle, |
| 32 | + getByDisplayValue, |
| 33 | + getAllByDisplayValue, |
| 34 | + queryAllByDisplayValue, |
| 35 | + queryByDisplayValue, |
| 36 | + findByDisplayValue, |
| 37 | + findAllByDisplayValue, |
| 38 | + getByRole, |
| 39 | + getAllByRole, |
| 40 | + queryAllByRole, |
| 41 | + queryByRole, |
| 42 | + findByRole, |
| 43 | + findAllByRole, |
| 44 | + getByTestId, |
| 45 | + getAllByTestId, |
| 46 | + queryAllByTestId, |
| 47 | + queryByTestId, |
| 48 | + findByTestId, |
| 49 | + findAllByTestId, |
| 50 | +} from '..' |
| 51 | + |
| 52 | +describe('synchronous queries throw on invalid container type', () => { |
| 53 | + test.each([ |
| 54 | + ['getByLabelText', getByLabelText], |
| 55 | + ['getAllByLabelText', getAllByLabelText], |
| 56 | + ['queryByLabelText', queryByLabelText], |
| 57 | + ['queryAllByLabelText', queryAllByLabelText], |
| 58 | + ['getByPlaceholderText', getByPlaceholderText], |
| 59 | + ['getAllByPlaceholderText', getAllByPlaceholderText], |
| 60 | + ['queryByPlaceholderText', queryByPlaceholderText], |
| 61 | + ['queryAllByPlaceholderText', queryAllByPlaceholderText], |
| 62 | + ['getByText', getByText], |
| 63 | + ['getAllByText', getAllByText], |
| 64 | + ['queryByText', queryByText], |
| 65 | + ['queryAllByText', queryAllByText], |
| 66 | + ['getByAltText', getByAltText], |
| 67 | + ['getAllByAltText', getAllByAltText], |
| 68 | + ['queryByAltText', queryByAltText], |
| 69 | + ['queryAllByAltText', queryAllByAltText], |
| 70 | + ['getByTitle', getByTitle], |
| 71 | + ['getAllByTitle', getAllByTitle], |
| 72 | + ['queryByTitle', queryByTitle], |
| 73 | + ['queryAllByTitle', queryAllByTitle], |
| 74 | + ['getByDisplayValue', getByDisplayValue], |
| 75 | + ['getAllByDisplayValue', getAllByDisplayValue], |
| 76 | + ['queryByDisplayValue', queryByDisplayValue], |
| 77 | + ['queryAllByDisplayValue', queryAllByDisplayValue], |
| 78 | + ['getByRole', getByRole], |
| 79 | + ['getAllByRole', getAllByRole], |
| 80 | + ['queryByRole', queryByRole], |
| 81 | + ['queryAllByRole', queryAllByRole], |
| 82 | + ['getByTestId', getByTestId], |
| 83 | + ['getAllByTestId', getAllByTestId], |
| 84 | + ['queryByTestId', queryByTestId], |
| 85 | + ['queryAllByTestId', queryAllByTestId], |
| 86 | + ])('%s', (_queryName, query) => { |
| 87 | + expect(() => |
| 88 | + query('invalid type for container', 'irrelevant text'), |
| 89 | + ).toThrowErrorMatchingInlineSnapshot( |
| 90 | + `"Expected container to be an Element, a Document or a DocumentFragment but got string."`, |
| 91 | + ) |
| 92 | + }) |
| 93 | +}) |
| 94 | + |
| 95 | +describe('asynchronous queries throw on invalid container type', () => { |
| 96 | + test.each([ |
| 97 | + ['findByLabelText', findByLabelText], |
| 98 | + ['findAllByLabelText', findAllByLabelText], |
| 99 | + ['findByPlaceholderText', findByPlaceholderText], |
| 100 | + ['findAllByPlaceholderText', findAllByPlaceholderText], |
| 101 | + ['findByText', findByText], |
| 102 | + ['findAllByText', findAllByText], |
| 103 | + ['findByAltText', findByAltText], |
| 104 | + ['findAllByAltText', findAllByAltText], |
| 105 | + ['findByTitle', findByTitle], |
| 106 | + ['findAllByTitle', findAllByTitle], |
| 107 | + ['findByDisplayValue', findByDisplayValue], |
| 108 | + ['findAllByDisplayValue', findAllByDisplayValue], |
| 109 | + ['findByRole', findByRole], |
| 110 | + ['findAllByRole', findAllByRole], |
| 111 | + ['findByTestId', findByTestId], |
| 112 | + ['findAllByTestId', findAllByTestId], |
| 113 | + ])('%s', (_queryName, query) => { |
| 114 | + const queryOptions = {} |
| 115 | + const waitOptions = {timeout: 1} |
| 116 | + return expect( |
| 117 | + query( |
| 118 | + 'invalid type for container', |
| 119 | + 'irrelevant text', |
| 120 | + queryOptions, |
| 121 | + waitOptions, |
| 122 | + ), |
| 123 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 124 | + `"Expected container to be an Element, a Document or a DocumentFragment but got string."`, |
| 125 | + ) |
| 126 | + }) |
| 127 | +}) |
0 commit comments