Skip to content

Commit ea5e76b

Browse files
committed
04/02: add expect scoping to the exercise
1 parent 20a0b23 commit ea5e76b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

β€Žexercises/04.performance/02.problem.concurrency/src/one.test.tsβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { setTimeout } from 'node:timers/promises'
33
for (let i = 0; i < 100; i++) {
44
// 🐨 Replace the `test()` function below with `test.concurrent()`.
55
// This will make all the test cases in this test file run simultaneously.
6-
test(`${i}`, async ({ expect }) => {
6+
//
7+
// 🐨 Spread the test context argument here and reference the `expect`
8+
// function from that object.
9+
// πŸ’° async ({ expect }) => {}
10+
test(`${i}`, async () => {
711
await setTimeout(25)
812
expect(i).toBe(i)
913
})

β€Žexercises/04.performance/02.problem.concurrency/src/two.test.tsβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { setTimeout } from 'node:timers/promises'
33
for (let i = 0; i < 100; i++) {
44
// 🐨 Replace the `test()` function below with `test.concurrent()`.
55
// This will make all the test cases in this test file run simultaneously.
6-
test(`${i}`, async ({ expect }) => {
6+
//
7+
// 🐨 Spread the test context argument here and reference the `expect`
8+
// function from that object.
9+
// πŸ’° async ({ expect }) => {}
10+
test(`${i}`, async () => {
711
await setTimeout(25)
812
expect(i).toBe(i)
913
})

β€Žexercises/04.performance/02.solution.concurrency/README.mdxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Vitest runs each test case in a test file _sequentially_. We can speed up our te
44

55
```diff filename=your.test.ts remove=1 add=2
66
test(`${i}`, () => {})
7-
test.concurrent(`${i}`, () => {})
7+
test.concurrent(`${i}`, async () => {})
88
// πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†
99
```
1010

@@ -14,7 +14,7 @@ By making our test cases concurrent, we can switch from a test waterfall to a fl
1414

1515
Now that our test run at the same time, it is absolutely crucial we provision proper _test isolation_. We don't want tests to be stepping on each other's toes and becoming flaky as a result. This often comes down to eliminating or replacing any shared (or global) state in test cases.
1616

17-
For example, ...
17+
For example, the `expect()` function that you use to make assertions _might contain state_. It is essential we scoped that function to individual test case by accessing it from the test context object:
1818

1919
```ts diff remove=1 add=3
2020
test.concurrent(`${i}`, async () => {

0 commit comments

Comments
Β (0)