2
2
3
3
<p align =" center " ><i >Simple http mocking, with good developer experience</i ></p >
4
4
5
- - [ Use it tests] ( #usage-in-tests-🧪 ) - mock API calls, with [ good practices enforced] ( #whats-different-from-other-http-mocking-libraries )
6
- - [ Use it in the browser or React Native apps] ( #usage-in-an-app-📱🖥️ ) - during development, or for a "demo mode"
5
+ - [ Use it tests 🧪 ] ( #usage-in-tests ) - mock API calls, with [ good practices enforced] ( #whats-different-from-other-http-mocking-libraries )
6
+ - [ Use it in the browser 🖥️ or React Native apps 📱 ] ( #usage-in-an-app ) - during development, or for a "demo mode"
7
7
8
8
---
9
9
@@ -14,11 +14,11 @@ yarn add --dev @matthieug/shm
14
14
| Platform | Status | Notes |
15
15
| ------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
16
16
| ` node ` / ` jest ` | ✅ | node>=18 required |
17
- | ` node ` / ` jest ` / ` jsdom ` | 🧑💻 | [ Polyfills required] ( https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest ) |
17
+ | ` node ` / ` jest ` / ` jsdom ` | ✅ | [ Polyfills required] ( https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest ) |
18
18
| ` node ` / ` vitest ` | ✅ | node>=18 required |
19
19
| ` bun ` with ` bun test ` | ⚠️ | test won't fail with ` afterEach(expectRequestsToMatchHandlers) ` |
20
20
| ` expo ` | ✅ | Install [ react-native-url-polyfill] ( https://github.com/charpeni/react-native-url-polyfill ) if using SDK < 50 |
21
- | ` react-native ` | 🧑💻 | Install [ react-native-url-polyfill] ( https://github.com/charpeni/react-native-url-polyfill ) |
21
+ | ` react-native ` | ✅ | Install [ react-native-url-polyfill] ( https://github.com/charpeni/react-native-url-polyfill ) |
22
22
| browser | ✅ | |
23
23
24
24
## Basic usage
@@ -55,7 +55,12 @@ mockServer.get<BodyType>("item/:id", {
55
55
56
56
Have a look at the [ type definitions] ( ./src/types.ts ) for more details.
57
57
58
- ## Usage in tests 🧪
58
+ ** Important notes:**
59
+
60
+ - Handlers will by default only respond to ** ONE** matching request. After that, they will be "consumed"
61
+ - Handlers are used in a _ first_in_first_out_ order
62
+
63
+ ## Usage in tests
59
64
60
65
### Setup
61
66
@@ -135,7 +140,7 @@ We want to promote a certain way to define and use api mocks in tests, and provi
135
140
- Check that your code is sending the correct request through ** assertions** , instead of by coincidentally definining the right handler
136
141
- Prefer specifying the necessary mocks for each test, so that you ** know at a glance what APIs your feature/component needs**
137
142
138
- ## Usage in an app 📱🖥️
143
+ ## Usage in an app
139
144
140
145
``` ts
141
146
import { installInterceptor , createMockServer , uninstallInterceptor } from " @matthieug/shm" ;
0 commit comments