@@ -2,6 +2,7 @@ export const metadata = {
2
2
title: ' Better mocks in Vitest' ,
3
3
description: ' Introducing vitest-when: better mocking in Vitest' ,
4
4
posted: ' 2023-06-30' ,
5
+ updated: ' 2023-08-04' ,
5
6
}
6
7
7
8
Mocking is a fantastic tool for writing high-quality unit tests, but ** nothing
@@ -52,7 +53,7 @@ test('stub something', () => {
52
53
In the above example, the ` sayHello ` stub behaves accordingly:
53
54
54
55
- When ` sayHello ` is called with ` Alice ` , it will return ` Hello, Alice `
55
- - When ` sayHello ` is called with ` Box ` , it will return ` Hey, Bob `
56
+ - When ` sayHello ` is called with ` Bob ` , it will return ` Hey, Bob `
56
57
- When ` sayHello ` is called in any other way, it will return ` undefined `
57
58
58
59
Stubs are useful when you're mocking a function that returns data. You set up a
@@ -208,7 +209,7 @@ expect(sayHello).toHaveBeenCalledWith('Alice') // assert cause
208
209
209
210
The argument assertion lives after, and away from, the return value, making the
210
211
test harder to read and maintain compared to vitest-when's strategy of
211
- configuring a cause and effect.
212
+ configuring a cause and effect at the same time .
212
213
213
214
You also perform an _ assertion_ to check the arguments, which is a more forceful
214
215
check that vitest-when's "filter by arguments and no-op otherwise" strategy.
0 commit comments