There’s probably a better word for it. I mean the component parts of a unit that require testing. In my case, the unit is a React component, and the subunits are the conditional JSX elements it renders.
This is a simplified version:
const Sidebar = (props) => {
const { user = {} } = props;
//render
return (
<div>
<p>{`Hi, ${user.name || "Anonymous"}!`}</p>
<hr />
<button>{user.auth ? "Logout" : "Login"}</button>
</div>
);
};
If defined, user
has the following (simplified) schema:
{
name: "",
auth: {
provider: "",
id: ""
}
}
I can think of four ways to test this:
- Test the default case and the case where
user.name
anduser.auth
are defined. This covers all branches and both common scenarios. - Additionally test the case where only
user.auth
is defined. This covers all scenarios. - Additionally test the case where only
user.name
is defined. This covers all paths. - Test the
p
andbutton
elements as separate components. This has the side benefit of greater reusability.