Skip to content

Commit 50952e9

Browse files
committed
update readme
1 parent 5bbb6f8 commit 50952e9

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • 05-testing/01-react/01-base/02-calculator

05-testing/01-react/01-base/02-calculator/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ _./src/calculator.spec.ts_
7878
- It should have same fields, even undefined values.
7979
- We should use `toEqual` if we don't care about it.
8080

81-
8281
## Spy
8382

8483
Now, we need passing a method as parameter, whatever it is, we only want to check that it was called and with which arguments:
@@ -476,13 +475,26 @@ describe('Calculator tests', () => {
476475
...
477476

478477
```
478+
479479
> [vi.mock](https://vitest.dev/api/vi.html#vi-mock)
480480
>
481481
> Notice that we don't see any `console.log` from original `isLowerThan` method.
482482
>
483483
> In this case we can also use `vi.mocked` instead of `vi.spyOn`: `vi.mocked(business.isLowerThan).mockImplementation(...)`
484-
>
485-
> Another use case is to [enable esModule support for a module that doesn't support it](https://github.com/vitest-dev/vitest/issues/3152#issuecomment-1566327217).
484+
485+
Another use case is to [enable esModule support for a module that doesn't support it](https://github.com/vitest-dev/vitest/issues/3152#issuecomment-1566327217).
486+
487+
```js
488+
import thirdParty from 'third-party';
489+
490+
vi.mock('third-party', async (importOriginal) => {
491+
const original = await importOriginal();
492+
return {
493+
...original,
494+
__esModule: true,
495+
};
496+
});
497+
```
486498

487499
# About Basefactor + Lemoncode
488500

0 commit comments

Comments
 (0)