[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

docs: update jest migration section with promise mock result (#5180)

Co-authored-by: Ivan Radonov <ivan.radonov@ad.mentormate.bg>

authored by

iradonov
Ivan Radonov
and committed by
GitHub
(Feb 13, 2024, 8:58 AM +0100) efa21e08 3ffcd2ea

+10
+10
docs/guide/migration.md
··· 186 186 const { cloneDeep } = await vi.importActual('lodash/cloneDeep') // [!code ++] 187 187 ``` 188 188 189 + ### Accessing the Return Values of a Mocked Promise 190 + 191 + 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. 192 + However, when mocking or spying on a promise (e.g. using `mockResolvedValue`), in Jest the `value` property will be a promise, while in Vitest, it will become a resolved value when a promise is resolved. 193 + 194 + ```ts 195 + await expect(spy.mock.results[0].value).resolves.toBe(123) // [!code --] 196 + expect(spy.mock.results[0].value).toBe(123) // [!code ++] 197 + ``` 198 + 189 199 ### Envs 190 200 191 201 Just like Jest, Vitest sets `NODE_ENV` to `test`, if it wasn't set before. Vitest also has a counterpart for `JEST_WORKER_ID` called `VITEST_POOL_ID` (always less than or equal to `maxThreads`), so if you rely on it, don't forget to rename it. Vitest also exposes `VITEST_WORKER_ID` which is a unique ID of a running worker - this number is not affected by `maxThreads`, and will increase with each created worker.