Skip to content

Commit ee0172c

Browse files
committed
add module 5
1 parent b829e5a commit ee0172c

23 files changed

+470
-17
lines changed

demo-app/src/assets/discoveries.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ fetch('/api/v1/discoveries')
1818
)
1919
.join('');
2020
target.innerHTML = html;
21+
})
22+
.catch(() => {
23+
target.innerHTML = lang === 'fr' ? 'Une erreur est survenue... 😰' : 'An error occurred... 😰';
2124
});
30.5 KB
Loading
22.5 KB
Loading
21.2 KB
Loading
21.3 KB
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- .slide: class="transition" -->
2+
3+
# Data strategies
4+
5+
##==##
6+
7+
# Use real services
8+
9+
![center h-800](./assets/images/05-test-data-and-mocks/app-archi-overview.drawio.png)
10+
11+
Notes:
12+
- E2E
13+
14+
##==##
15+
16+
# Mock external servers (pretty much E2E)
17+
18+
![center h-800](./assets/images/05-test-data-and-mocks/strat-mock-external-servers.png)
19+
20+
Notes:
21+
- E2E on the "team" point of view
22+
23+
##==##
24+
25+
# Mock every API calls (aka UI tests)
26+
27+
![center h-800](./assets/images/05-test-data-and-mocks/strat-mock-all-calls.png)
28+
29+
##==##
30+
31+
# Mock only difficult use case with Playwright
32+
33+
![center h-800](./assets/images/05-test-data-and-mocks/strat-mock-some-calls.png)
34+
35+
Notes:
36+
- do we really need to tests theses cases?
37+
38+
##==##
39+
40+
<!-- .slide: class="quote-slide" -->
41+
42+
## More you mock,
43+
## More your are stable,
44+
## BUT less you test the reality.
45+
46+
Notes:
47+
- always a balance between stability / realism / testability
48+
- some cases need mocks
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- .slide: class="transition" -->
2+
3+
# API Call mocks
4+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!-- .slide: class="transition" -->
2+
3+
# How to do it with Playwright?
4+
5+
##==##
6+
7+
<!-- .slide: class="with-code" -->
8+
9+
# Build a fake OK response
10+
11+
```TypeScript [2-5]
12+
test('...', async ({ page }) => {
13+
await page.route('*/**/api/v1/fruits', async route => {
14+
const json = [{ name: 'Strawberry', id: 21 }];
15+
await route.fulfill({ json });
16+
});
17+
18+
await page.goto('/');
19+
});
20+
```
21+
<!-- .element: class="big-code" -->
22+
23+
Notes:
24+
- create an interception of the api calls
25+
- you can read the request and build a new response
26+
27+
##==##
28+
29+
<!-- .slide: class="with-code" -->
30+
31+
# Build a fake KO response
32+
33+
```TypeScript [2-5]
34+
test('...', async ({ page }) => {
35+
await page.route('*/**/api/v1/fruits', async route => {
36+
await route.fulfill({ status: 404 });
37+
});
38+
39+
await page.goto('/');
40+
});
41+
```
42+
<!-- .element: class="big-code" -->
43+
44+
Notes:
45+
- create an interception of the api calls
46+
- you can read the request and build a new response
47+
48+
49+
##==##
50+
51+
<!-- .slide: class="with-code" -->
52+
53+
# Edit real response response
54+
55+
```TypeScript [2-5]
56+
test('...', async ({ page }) => {
57+
await page.route('*/**/api/v1/fruits', async route => {
58+
const response = await route.fetch();
59+
const json = await response.json();
60+
json.push({ name: 'Loquat', id: 100 });
61+
await route.fulfill({ response, json });
62+
});
63+
64+
await page.goto('/');
65+
});
66+
```
67+
<!-- .element: class="big-code" -->
68+
69+
Notes:
70+
- keep the real response, but patch it with the given json
71+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- .slide: class="transition" -->
2+
3+
# Is it always possible?
4+
5+
##==##
6+
7+
<!-- .slide: class="transition-bg-blue-3 right" -->
8+
9+
# CSR vs SSR
10+
11+
Notes:
12+
- Client Side Rendering = Mostly SPA
13+
- SSR = Server Side Rendering
14+
- Not possible to mock API Call on SSR app

docs/markdown/05-test-data-and-mocks/99-lab-error-use-cases-through-mocks.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
<br>
88

9-
1. TODO
10-
2. TODO
11-
3. TODO
9+
1. Create a file `discoveries.spec.ts`
10+
2. Test errors on Discoveries loading on the home page
11+
3. Test the case where we only have 2 products in the discovery
1212

1313
<br>
1414

15-
- TODO
16-
1715
### npm run 04-mock-error-use-case

0 commit comments

Comments
 (0)