33This package contains common utilities for testing UI components across
44Hypothesis frontend projects. It includes tools for:
55
6+ - Rendering UI components and unmounting them once the test ends
67 - Waiting for conditions to be met
78 - Mocking UI components
89 - Testing accessibility using [ axe-core] ( https://github.com/dequelabs/axe-core )
@@ -14,3 +15,36 @@ standard UI and UI testing stack, built on:
1415 - [ Enzyme] ( https://github.com/enzymejs/enzyme )
1516 - [ babel-plugin-mockable-imports] ( https://github.com/robertknight/babel-plugin-mockable-imports )
1617
18+ ## API guide
19+
20+ ### Rendering components
21+
22+ This package exports a wrapper around Enzyme's ` mount ` function to render
23+ a component, query its output and interact with it. The function in this
24+ package adds the wrapper to a global list of active wrappers which can then
25+ be conveniently unmounted using ` unmountAll ` at the end of a test.
26+
27+ ``` js
28+ import { mount , unmountAll } from ' @hypothesis/frontend-testing' ;
29+
30+ describe (' MyWidget' , () => {
31+ afterEach (() => {
32+ // Clean up by unmounting any wrappers mounted in the current test and
33+ // removing associated DOM containers.
34+ unmountAll ();
35+ });
36+
37+ it (' should render' , () => {
38+ const wrapper = mount (< MyWidget/ > );
39+
40+ // Query component content etc.
41+ });
42+
43+ it (' should do something that requires component to be connected' , () => {
44+ const wrapper = mount (< MyWidget/ > , { connected: true });
45+
46+ // Test behavior that relies on rendered component being part of the
47+ // DOM tree under `document.body`.
48+ });
49+ });
50+ ```
0 commit comments