You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/modules/4-advanced/testing.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,62 @@ test('CurveTab', () => {
45
45
46
46
For more instructions on how to write tests you can refer to the [Vitest website](https://vitest.dev/guide/#writing-tests).
47
47
48
+
### Test Filtering
49
+
50
+
> [!INFO]
51
+
> More information on this entire section can be found [here](https://vitest.dev/guide/filtering.html#skipping-suites-and-tests);
52
+
53
+
While writing tests, you might find that you might want to focus on a single test or single group of tests. For this, `vitest` provides on its `test`, `it` and `describe` functions
54
+
a `.skip` and a `.only` property:
55
+
```ts
56
+
describe('Test1 and Test3 will run!', () => {
57
+
test('Test1', () => {});
58
+
test.skip('Test2', () => {});
59
+
test('Test3', () => {})
60
+
});
61
+
```
62
+
You don't have to comment out your tests; simply use `.skip` to indicate that a test block should not be executed.
63
+
64
+
If for some reason you want to skip your tests based on some condition, `vitest` provides the `skipIf` property:
65
+
```ts
66
+
describe('Test1 and Test3 will run!', () => {
67
+
test('Test1', () => {});
68
+
test.skipIf(condition)('Test2', () => {});
69
+
test('Test3', () => {})
70
+
});
71
+
```
72
+
73
+
`.only` is kind of the reverse of `.skip`. Tests that you use `.only` with will be the **only** tests that run in that file:
74
+
```ts
75
+
describe('Only Test 2 will run!', () => {
76
+
test('Test1', () => {});
77
+
test.only('Test2', () => {});
78
+
test('Test3', () => {})
79
+
});
80
+
```
81
+
The main runner that runs unit tests on the CI/CD pipeline does not allow for `.only`. You can simulate this behaviour by running your tests with the
82
+
`--no-allow-only` flag. This behaviour is intended to prevent you from causing only part of your tests to run.
83
+
84
+
> [!INFO] Linting
85
+
> There is an ESLint rule configured to warn you if you use focused tests (using `.only`). This is not an issue, so long as you remember
86
+
> to remove `.only` before pushing to the main repository.
87
+
88
+
Pushing with skipped tests however, is allowed. Do leave a comment explaining why the test is skipped:
89
+
```ts
90
+
// Test is skipped because there is an outstanding bug
91
+
test.skip('Test path resolution', () => {})
92
+
```
93
+
94
+
### Stubbing Tests
95
+
If you want to indicate that tests should be written for certain functionality in the future, you can use `.todo`:
96
+
97
+
```ts
98
+
// Needs to be implemented when the outstanding bug is fixed
99
+
test.todo('Test path resolution')
100
+
```
101
+
102
+
TODO tests still generate an entry in your test reports, but will be considered neither failed nor passed.
103
+
48
104
## Running Tests
49
105
To run tests for a given bundle or tab, simply run either of the following commands within the directory:
50
106
```sh
@@ -56,6 +112,8 @@ By default, `vitest` will quit after running tests. If you wish to run the tests
56
112
57
113
You can also use `--update` to update snapshots and `--coverage` to run the V8 coverage reporter.
58
114
115
+
For bundles and tabs, the test environment should always be `jsdom`, since they are intended for the browser.
116
+
59
117
## Integration with Git Hooks
60
118
Any tests that you have written must be pass in order for you to push to the main repository, as well as for your pull requests to be merged.
0 commit comments