React Browser Tests
  • Home
  • Components
    • Test Container
    • Test
    • Test Group
    • Single Test Container Overview
    • Multiple Test Container Overview
    • Multiple Page Overview
    • Sidebar Layout
  • Helper Functions
  • Run in a Terminal
  • Tests

<Test>

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

Example in a NextJS page:

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:

Expect 1 + 1 to equal 2.

Props

title

Title of the test.

fn

Test function where the test is written. Can be async.

TitleAndState?

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.

skip?

Boolean - skips the test if set to true.

only?

Boolean - only runs this test if set to true.

HTMLDivElement props

Supports standard HTMLDivElement props. For example: className, style, etc.