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: test/README.md
+1-30
Original file line number
Diff line number
Diff line change
@@ -33,36 +33,7 @@ See [`test/integration/README.md`](./integration/README.md).
33
33
-**You should not mock any internal domain objects.** Internal domain objects include `Style`, `Map`, `Transform`, and `Dispatcher`. If this is difficult because of some interface, refactor that interface. This ensures that tests accurately exercise the code paths used in production.
34
34
-**You should test one return value or side effect per test case.** Feel free to pull shared logic into a function. This ensures that tests are easy to understand and modify.
35
35
-**You should only test the return values and global side effects of methods.** You should not not test internal behavior, such as that another method is called with particular arguments. This ensures that method implementations may change without causing test failures.
36
-
-**You must not make network requests in test cases.** This rule holds in cases when result isn't used or is expected to fail. You may use `getNetworkWorker` from `test/util/network.js` module, which uses [`mswj`](https://mswjs.io/docs/api/setup-worker/) to simulate network requests. This ensures that tests are reliable, able to be run in an isolated environment, and performant. In your test suite you can setup network worker in the following way:
37
-
```js
38
-
let networkWorker;
39
-
40
-
beforeAll(async () => {
41
-
networkWorker =awaitgetNetworkWorker(window);
42
-
});
43
-
44
-
afterEach(() => {
45
-
// Clear runtime mocks, which were added by `.use`
46
-
networkWorker.resetHandlers();
47
-
});
48
-
49
-
afterAll(() => {
50
-
networkWorker.stop();
51
-
});
52
-
53
-
test('should tests something', () => {
54
-
networkWorker.use(
55
-
http.get('/notfound.png', async () => {
56
-
returnnewHttpResponse(null, {status:404});
57
-
}),
58
-
http.get('/style.json', async () => {
59
-
returnHttpResponse.json({});
60
-
})
61
-
);
62
-
63
-
// Network mocks are ready: act and assert
64
-
});
65
-
```
36
+
-**You must not make network requests in test cases.** This rule holds in cases when result isn't used or is expected to fail. You may use `mockFetch` from `test/util/network.js` module to mock requests if you need though. This ensures that tests are reliable, able to be run in an isolated environment, and performant
66
37
-**You should use clear [input space partitioning](http://crystal.uta.edu/~ylei/cse4321/data/isp.pdf) schemes.** Look for edge cases! This ensures that tests suites are comprehensive and easy to understand.
67
38
68
39
If you want to debug your unit tests you can open UI for that with the following command:
0 commit comments