Skip to content

Commit 0b20ee7

Browse files
committed
02: add intro and outro
1 parent 19a31e7 commit 0b20ee7

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

exercises/02.context/FINISHED.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# Context
22

3-
Great job! :tada: Take a rest and let's continue.
3+
Yay! :tada: And so concludes the block dedicated to the test context and custom fixtures.
4+
5+
The importance of the test setup cannot be overstated. Developers often forget to pay due attention to preparing those building blocks and jump straight into test cases. But that's like rushing to cook a dish without buying and preparing all the ingredients first. That is a recipe for disaster.
6+
7+
Now you know how to create those building blocks—your fixtures. But the customization story doesn't end here.
8+
9+
Take a break, stretch a little, and get ready to explore assertions, matchers, and equality testers!

exercises/02.context/README.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
# Context
22

3-
There's nothing for you to read here but I will have a lot to say on this topic once we come to this exercise!
3+
A properly orchestrated test feels like putting LEGO pieces together:
4+
5+
```ts highlight=2-4
6+
// Arrange.
7+
mockDatabase(process.env.DB_URL)
8+
mockApi(...handlers)
9+
authenticate({ as: 'admin' })
10+
11+
const api = new System()
12+
13+
// Act.
14+
api.act()
15+
16+
// Assert.
17+
expect(api.state).toEqual(expectedState)
18+
```
19+
20+
Notice how you can understand what the highlighted functions do even without knowing how the specifics of their implementation. While that can be largely attributed to their names, there's another thing at work here.
21+
22+
<callout-success>These functions reflect the complexity of this test without allowing that complexity to leak into the test itself.</callout-success>
23+
24+
That is precisely the point of the test setup. Because behind the scenes `mockDatabase()` and `mockApi()` and `authenticate()` can be quite complex in their own right as they prepare the ground for any test to run. But as far as your test cases are concerned, none of that complexity matters.
25+
26+
For your test cases, arranging even the most complex scenarios still comes down to putting the setup bricks together.
27+
28+
But where do those functions come from? Where do you get the bricks?
29+
30+
Well, you create them yourself! But you aren't left in the dark here because modern testing frameworks not only allow you to do that elegantly but also have a proper name for those building blocks:
31+
32+
**Fixtures**.
33+
34+
In this exercise block, you will learn how to create your custom fixtures to improve the readability of your test cases while simultaneously addressing any complexity introduced by the tested system.

0 commit comments

Comments
 (0)