Skip to content

Commit

Permalink
docs: start migration guide from Jest (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvHaus committed Feb 13, 2022
1 parent c8a6f4b commit 51d751c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/.vitepress/config.ts
Expand Up @@ -127,7 +127,11 @@ export default defineConfig({
{
text: 'Comparisons',
link: '/guide/comparisons'
}
},
{
text: 'Migration Guide',
link: '/guide/migration'
},
]
},
/* TODO
Expand Down
2 changes: 0 additions & 2 deletions docs/api/index.md
Expand Up @@ -1100,8 +1100,6 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
- If `__mocks__` folder with file of the same name exist, all imports will return its exports. For example, `vi.mock('axios')` with `<root>/__mocks__/axios.ts` folder will return everything exported from `axios.ts`.
- If there is no `__mocks__` folder or a file with the same name inside, will call original module and mock it. (For the rules applied, see [algorithm](/guide/mocking#automocking-algorithm).)

Additionally, unlike Jest, mocked modules in `<root>/__mocks__` are not loaded unless `vi.mock()` is called. If you need them to be mocked in every test, like in Jest, you can mock them inside [`setupFiles`](/config/#setupfiles).

### vi.setSystemTime

- **Type**: `(date: string | number | Date) => void`
Expand Down
21 changes: 21 additions & 0 deletions docs/guide/migration.md
@@ -0,0 +1,21 @@
# Migration Guide

<DevelopmentWarning/>

## Migrating from Jest

Vitest has been designed with a Jest compatible API, in order to make the migration from Jest as simple as possible. Despite those efforts, you may still run into the following differences:

**Globals as a Default**

Jest has their [globals API](https://jestjs.io/docs/api) enabled by default. Vitest does not. You can either enable globals via [the `globals` configuration setting](/config/#globals) or update your code to use imports from the `vitest` module instead.

If you decide to keep globals disabled, be aware that common libraries like [`testing-library`](https://testing-library.com/) will not run auto DOM [cleanup](https://testing-library.com/docs/svelte-testing-library/api/#cleanup).

**Auto-Mocking Behaviour**

Unlike Jest, mocked modules in `<root>/__mocks__` are not loaded unless `vi.mock()` is called. If you need them to be mocked in every test, like in Jest, you can mock them inside [`setupFiles`](/config/#setupfiles).

**Jasmine API**

Jest exports various [`jasmine`](https://jasmine.github.io/) globals (such as `jasmine.any()`). Any such instances will need to be migrated to [their Vitest counterparts](/api/).

0 comments on commit 51d751c

Please sign in to comment.