-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test helpers file with `getByTextWithMarkup` and `waitForLoadingToFinish` helpers.
- Loading branch information
1 parent
f1fb520
commit 67d817a
Showing
7 changed files
with
45 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { screen, waitForElementToBeRemoved } from '@testing-library/react'; | ||
|
||
// Custom matcher that queries elements split up by multiple HTML elements by text | ||
export function getByTextWithMarkup(text: RegExp | string) { | ||
return screen.getByText((content, node) => { | ||
const hasText = (node: Element) => node.textContent === text || node.textContent.match(text); | ||
const childrenDontHaveText = Array.from(node.children).every((child) => !hasText(child as HTMLElement)); | ||
return hasText(node) && childrenDontHaveText; | ||
}); | ||
} | ||
|
||
export function waitForLoadingToFinish() { | ||
return waitForElementToBeRemoved(() => [...screen.queryAllByRole(/progressbar/i)], { | ||
timeout: 4000, | ||
}); | ||
} |