React Browser Tests exports multiple functions and hooks that can be used in tests. The main ones are:
Waits for a condition to be true. Receives a function that returns a boolean. Returns a promise that resolves when the function returns true, or rejects after a timeout.
Receives a containerState object and returns the array of tests from it.
Receives an array of tests and a group name. Returns an array with only the tests with the passed in group name.
These are re-exported from Chai.
The global window object has multiple functions available. They can be accessed through the window.reactBrowserTests
object. The type of this object is:
type ReactBrowserTestsWindowObject = {
testContainers: TestContainerState[];
getContainerState: (containerId?: string, windowRef?: Window) => TestContainerState | undefined;
getTestRecord: (containerId?: string, windowRef?: Window) => Record<string, TestType>;
getTestArray: (containerId?: string, windowRef?: Window) => TestType[];
checkIfContainerTestsComplete: (containerId?: string, windowRef?: Window) => boolean;
checkIfTestsFromAllContainersComplete: (windowRef?: Window) => boolean;
sumTotalNumberOfTests: (windowRef?: Window) => number | null;
checkIfAllTestsRegistered: (windowRef?: Window) => boolean;
}
Here's an example of how to fetch an array with all the tests:
const testArray = window.reactBrowserTests.getTestArray();
There are other functions available. Their source code is available on: