Executes a test function and shows the result in a browser. Optionally, the tests can run in a terminal, via a headless browser for example.
The tests in a <TestContainer> run sequentially. The child components of each <Test> component are only rendered when the test is running or has run.
<Test> components must have a <TestContainer> parent somewhere in the tree.
The test states are:
Pending - the test is waiting to start
Running - the test is currently running
Success - the test has passed
Fail - the test has failed
Skipped - the test was skipped
import { Test, TestContainer, expect } from "react-browser-tests";
export default function TestPage() {
return (
<TestContainer>
<Test title="Expect 1 + 1 to equal 2." fn={() => {
expect(1 + 1).to.equal(2);
}} />
</TestContainer>
);
}
If we navigate to that page, we'll see:
Title of the test.
Test function where the test is written. Can be async.
React component that shows the state and title of the test. If no component is passed in, the default component is used: <TitleAndStateDefault>. The props for this component are: test title and state.
Boolean - skips the test if set to true.
Boolean - only runs this test if set to true.
Supports standard HTMLDivElement props. For example: className
, style
, etc.