when mounted

  • <ReactElement> when mounted <assertion>

This will assertion will mount the JSX structure into the DOM and forward it to the next assertion.

Let's create a component for the example:

const React = require("react");
 
const Hello = ({ children }) => (
  <div>
    <span className="label">Hello</span>
    &nbsp;
    <span className="name">{children}</span>
  </div>
); 

Now we can mount it using the assertion and assert that I has the correct text using an unexpected-dom assertion:

expect(
  <Hello>Jane Doe</Hello>,
  'when mounted',
  'to have text', 'Hello Jane Doe'
);

This is similar to the mount function in the following way:

const { mount } = require('unexpected-reaction');
expect(
  mount(<Hello>Jane Doe</Hello>),
  'to have text', 'Hello Jane Doe'
);

The mount method is provided by react-dom-testing and is exported as a convenience.