Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Adds touch() function
lib.fireEvent.touch(elem); // $ExpectType Promise
// Reexports async functions from dom-testing-library
lib.wait(); // $ExpectType Promise
lib.wait(() => { throw new Error("nope"); }, {timeout: 3000, interval: 100});
lib.waitForDomChange({container: select, timeout: 3000, mutationObserverOptions: {subtree: false}});
lib.waitForElement(() => input); // $ExpectType Promise
lib.waitForElement(() => option, {container: select, timeout: 3000, mutationObserverOptions: {subtree: false}}); // $ExpectType Promise
lib.waitForElementToBeRemoved(() => input); // $ExpectType Promise
lib.waitForElementToBeRemoved(() => option, {container: select, timeout: 3000, mutationObserverOptions: {subtree: false}}); // $ExpectType Promise
// Reexports utilities from dom-testing-library
lib.buildQueries((el: HTMLElement) => [el], (_: HTMLElement) => "something", (_: HTMLElement) => "error");
lib.within(elem);
lib.getQueriesForElement(elem);
lib.getNodeText(elem); // $ExpectType string
lib.getRoles(elem); // $ExpectType { [index: string]: HTMLElement[]; }
lib.prettyDOM(elem); // $ExpectType string | false
lib.logRoles(elem); // $ExpectType string
`,
})
// getByText() provided by render() fails because it finds multiple elements
// with the same text (as expected).
expect(() => getByText('repeated text')).toThrow(
'Found multiple elements with the text: repeated text',
)
const divNode = getByTestId('div')
// within() returns queries bound to the provided DOM node, so the following
// assertion passes. Notice how we are not using the getByText() function
// provided by render(), but the one coming from within().
within(divNode).getByText('repeated text')
// Here, proof that there's only one match for the specified text.
expect(divNode).toMatchInlineSnapshot(`
<div data-testid="div">
repeated text
</div>
`)
})