
Company News
Socket Has Acquired Secure Annex
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.
test-drive-react
Advanced tools
Opinionated library for Test-Driven Development of React components, extending Test Drive and providing its DOM parts lookup, presence/absence matchers and event triggering layout matchers.
In addition, it reexports React simulate testing utility and integrated renderer
ClientRenderer provides a utility for rendering React components in consistent
and convenient way. It creates the holding container, if necessary, with uniform positioning,
automatically binds to it all important Test Drive helper functions, and proivides clean-up
mechanism.
For a typical use, see the end-to-end test.
The renderer is created simply by invoking new ClientRenderer().
render(element, container?)Renders the element React component. If container is not specified, a new one is created.
Returns RenderingContext with following fields:
containerresult - rendered root component (either DOM Element or React component instance)select - DOM selector
pre-bound to the containercleanup()Unmounts the root component and removes any container that had been created by the renderer.
Test Drive React provides additional layer of abstraction over the basic assertion tools. In order to keep the intended behavior of a component separated from the actual implementation (DOM structure, particular DOM events, etc.), every component should provide it's "driver". Component driver translates meaningful actions and getters into specific DOM details.
All drivers should extend the DriverBase class. The basic (and recommended) way of creating drivers is to use
.withDriver(DriverClass) method which is part of the RenderingContext interface.
For example, consider a TestComponent. There should be always
relevant implementation of its driver, e.g.:
export class TestComponentDriver extends DriverBase<HTMLElement> {
static ComponentClass = TestComponent;
get samplePart() {
return this.ensuredSelect('SAMPLE_PART') as HTMLDivElement;
}
doAction() {
this.root.click();
}
}
The ComponentClass points to the component for which is the driver relevant. It is used by the
ClientRenderer for validation of a component/driver match during the rendering. (This validation
is intended to prevent using a wrong driver on top of a DOM generated by a component.)
The getter .samplePart provides access (via data-automation-id) to specific parts of
the component's shadow DOM, while keeping this detail encapsulated. Similarly,
the .doAction() method represents specific methods, while keeping the technicalities (event type)
private.
The driver then should be instantiated and used through ClientRenderer, e.g.:
const { driver } = clientRenderer.render(<TestComponent />).withDriver(TestComponentDriver);
expect(driver.samplePart).to.be.present();
Note that the .withDriver() function returns RenderingContextWithDriver, which has following
members:
driver - instance of the component driverIn the case of composite components, the drivers should mirror their structure as well. .samplePart in
the above example should, therefore, reference another (relevant) component driver, rather than plain DOM Element,
if it corresponds to custom component.
MIT
FAQs
Opinionated library for Test-Driven Development of React Components.
The npm package test-drive-react receives a total of 30 weekly downloads. As such, test-drive-react popularity was classified as not popular.
We found that test-drive-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.

Research
/Security News
Socket is tracking cloned Open VSX extensions tied to GlassWorm, with several updated from benign-looking sleepers into malware delivery vehicles.

Product
Reachability analysis for PHP is now available in experimental, helping teams identify which vulnerabilities are actually exploitable.