3
3
This package contains common utilities for testing UI components across
4
4
Hypothesis frontend projects. It includes tools for:
5
5
6
- - Rendering UI components and unmounting them once the test ends
7
- - Waiting for conditions to be met
8
- - Mocking UI components
9
- - Testing accessibility using [ axe-core] ( https://github.com/dequelabs/axe-core )
6
+ - Rendering UI components and unmounting them once the test ends
7
+ - Waiting for conditions to be met
8
+ - Mocking UI components
9
+ - Testing accessibility using [ axe-core] ( https://github.com/dequelabs/axe-core )
10
10
11
11
This package is designed to work with downstream projects that use Hypothesis's
12
12
standard UI and UI testing stack, built on:
13
13
14
- - [ Preact] ( https://preactjs.com )
15
- - [ Enzyme] ( https://github.com/enzymejs/enzyme )
16
- - [ Vitest] ( http://vitest.dev/ )
17
- - [ babel-plugin-mockable-imports] ( https://github.com/robertknight/babel-plugin-mockable-imports )
14
+ - [ Preact] ( https://preactjs.com )
15
+ - [ Enzyme] ( https://github.com/enzymejs/enzyme )
16
+ - [ Vitest] ( http://vitest.dev/ )
17
+ - [ babel-plugin-mockable-imports] ( https://github.com/robertknight/babel-plugin-mockable-imports )
18
18
19
19
## API guide
20
20
@@ -36,13 +36,13 @@ describe('MyWidget', () => {
36
36
});
37
37
38
38
it (' should render' , () => {
39
- const wrapper = mount (< MyWidget/ > );
39
+ const wrapper = mount (< MyWidget / > );
40
40
41
41
// Query component content etc.
42
42
});
43
43
44
44
it (' should do something that requires component to be connected' , () => {
45
- const wrapper = mount (< MyWidget/ > , { connected: true });
45
+ const wrapper = mount (< MyWidget / > , { connected: true });
46
46
47
47
// Test behavior that relies on rendered component being part of the
48
48
// DOM tree under `document.body`.
@@ -58,30 +58,30 @@ However, we don't follow all practices recommended by Vitest. You should take
58
58
these points into consideration when reading Vitest's documentation:
59
59
60
60
1 . By default, Vitest uses [ Vite] ( https://vite.dev/ ) to bundle the tests and
61
- source code as test files are run.
62
- Instead, we manually pre-bundle our tests and source code in a single file
63
- with Rollup, and that's the only test file we run.
64
- That file is still processed by Vite, but since it has nothing to transform,
65
- the time it takes is negligible.
61
+ source code as test files are run.
62
+ Instead, we manually pre-bundle our tests and source code in a single file
63
+ with Rollup, and that's the only test file we run.
64
+ That file is still processed by Vite, but since it has nothing to transform,
65
+ the time it takes is negligible.
66
66
2 . Due to the point above, Vitest tries to capture and calculate code coverage while
67
- tests and sources are bundled with Vite.
68
- In our case, we use ` babel-plugin-istanbul ` to instrument the code coverage
69
- while we do our own pre-bundling.
70
- This requires two configuration options to be set in ` babel-plugin-istanbul ` ,
71
- so that ` istanbul-lib-instrument ` checks the file is already instrumented.
72
- See the details below .
73
-
74
- ``` js
75
- [
76
- ' babel-plugin-istanbul' ,
77
- {
78
- coverageGlobalScope: ' globalThis' ,
79
- coverageVariable: ' __VITEST_COVERAGE__' ,
80
-
81
- // Other options...
82
- },
83
- ]
84
- ```
67
+ tests and sources are bundled with Vite.
68
+ In our case, we use ` babel-plugin-istanbul ` to instrument the code coverage
69
+ while we do our own pre-bundling.
70
+ This requires two configuration options to be set in ` babel-plugin-istanbul ` ,
71
+ so that ` istanbul-lib-instrument ` checks the file is already instrumented.
72
+ [ See the discussion ] ( https://github.com/vitest-dev/vitest/discussions/7841#discussioncomment-12855608 ) .
73
+
74
+ ``` js
75
+ [
76
+ ' babel-plugin-istanbul' ,
77
+ {
78
+ coverageGlobalScope: ' globalThis' ,
79
+ coverageVariable: ' __VITEST_COVERAGE__' ,
80
+
81
+ // Other options...
82
+ },
83
+ ];
84
+ ```
85
85
86
86
### Istanbul coverage options
87
87
@@ -132,7 +132,6 @@ still prints the real-time summary and details for any failed test.
132
132
133
133
``` js
134
134
// vitest.config.js
135
-
136
135
import { SummaryReporter } from ' @hypothesis/frontend-testing' ;
137
136
import { defineConfig } from ' vitest/config' ;
138
137
0 commit comments