From 6abb170dc4d1e19a18cc74927ae127fa6ca41018 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Wed, 24 Apr 2024 16:26:53 +0200 Subject: [PATCH] docs: Updating migration guide file (jest -> vitest) Adding a small chapter to smooth the transition between jest to vitest when mocking a module that is used by external dependencies. --- docs/guide/migration.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/guide/migration.md b/docs/guide/migration.md index 07c6eee553e9..c4b43242f6bb 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -186,6 +186,14 @@ const { cloneDeep } = jest.requireActual('lodash/cloneDeep') // [!code --] const { cloneDeep } = await vi.importActual('lodash/cloneDeep') // [!code ++] ``` +### Extends mocking to external libraries + +Where Jest does it by default, when mocking a module and wanting this mocking to be extended to other external libraries that use the same module, you should explicitly tell which 3rd-party library you want to be mocked, so the external library would be part of your source code, by using [server.deps.inline](https://vitest.dev/config/#server-deps-inline). + +``` +server.deps.inline: ["lib-name"] +``` + ### Accessing the Return Values of a Mocked Promise Both Jest and Vitest store the results of all mock calls in the [`mock.results`](/api/mock.html#mock-results) array, where the return values of each call are stored in the `value` property.