|
| 1 | +import {configure} from '../config' |
1 | 2 | import {JSDOM} from 'jsdom'
|
2 | 3 | import * as dtl from '../'
|
3 | 4 |
|
@@ -77,6 +78,52 @@ test('works without a browser context on a dom node (JSDOM Fragment)', () => {
|
77 | 78 | `)
|
78 | 79 | })
|
79 | 80 |
|
| 81 | +test('works with a custom configured element query', () => { |
| 82 | + const container = JSDOM.fragment(` |
| 83 | + <html> |
| 84 | + <body> |
| 85 | + <form id="login-form"> |
| 86 | + <label for="username">Username</label> |
| 87 | + <input id="username" /> |
| 88 | + <label for="password">Password</label> |
| 89 | + <input id="password" type="password" /> |
| 90 | + <button type="submit">Submit</button> |
| 91 | + <div id="data-container"></div> |
| 92 | + </form> |
| 93 | + <form id="other"> |
| 94 | + <label for="user_other">Username</label> |
| 95 | + <input id="user_other" /> |
| 96 | + <label for="pass_other">Password</label> |
| 97 | + <input id="pass_other" type="password" /> |
| 98 | + <button type="submit">Submit</button> |
| 99 | + <div id="data-container"></div> |
| 100 | + </form> |
| 101 | + </body> |
| 102 | + </html> |
| 103 | + `) |
| 104 | + |
| 105 | + configure({ |
| 106 | + queryAllElements: (element, query) => |
| 107 | + element.querySelectorAll(`#other ${query}`), |
| 108 | + }) |
| 109 | + |
| 110 | + expect(dtl.getByLabelText(container, /username/i)).toMatchInlineSnapshot(` |
| 111 | + <input |
| 112 | + id=user_other |
| 113 | + /> |
| 114 | + `) |
| 115 | + expect(dtl.getByLabelText(container, /password/i)).toMatchInlineSnapshot(` |
| 116 | + <input |
| 117 | + id=pass_other |
| 118 | + type=password |
| 119 | + /> |
| 120 | + `) |
| 121 | + // reset back to original config |
| 122 | + configure({ |
| 123 | + queryAllElements: (element, query) => element.querySelectorAll(query), |
| 124 | + }) |
| 125 | +}) |
| 126 | + |
80 | 127 | test('byRole works without a global DOM', () => {
|
81 | 128 | const {
|
82 | 129 | window: {
|
|
0 commit comments