···1313Vitest 5.0 is currently in beta. This section tracks breaking changes as they are merged and may change before the stable release.
1414:::
15151616+### `clearMocks` is Enabled by Default
1717+1818+[`clearMocks`](/config/#clearmocks) now defaults to `true`. Vitest calls [`vi.clearAllMocks()`](/api/vi#vi-clearallmocks) before every test, resetting the `mock.calls`, `mock.instances`, `mock.contexts` and `mock.results` of every mock. Mock implementations are left intact, so this only affects the recorded history.
1919+2020+In practice this means a mock no longer carries calls from one test into the next:
2121+2222+```ts
2323+import { expect, test, vi } from 'vitest'
2424+2525+const fn = vi.fn()
2626+2727+test('first', () => {
2828+ fn()
2929+ expect(fn).toHaveBeenCalledTimes(1)
3030+})
3131+3232+test('second', () => {
3333+ fn()
3434+ // v4: the call from "first" was kept, so this was 2 // [!code --]
3535+ expect(fn).toHaveBeenCalledTimes(2) // [!code --]
3636+ // v5: history is cleared before each test, so only this test's call counts // [!code ++]
3737+ expect(fn).toHaveBeenCalledTimes(1) // [!code ++]
3838+})
3939+```
4040+4141+Tests that record calls outside of the test body (for example in a setup file, at the top level of a module, or in a `beforeAll` hook) are the most affected, because that history is cleared before the test that asserts on it runs.
4242+4343+To keep the previous behavior, set `clearMocks` back to `false`:
4444+4545+```ts [vitest.config.ts]
4646+import { defineConfig } from 'vitest/config'
4747+4848+export default defineConfig({
4949+ test: {
5050+ clearMocks: false, // [!code ++]
5151+ },
5252+})
5353+```
5454+1655### Benchmarking API Rewrite
17561857The benchmarking API has been rewritten. `bench` is no longer a top-level import from `vitest`; it is a [test-context fixture](/guide/test-context#bench) accessed from inside a regular `test()`. See the [Benchmarking guide](/guide/benchmarking) for the new API.
···1616 mockedB()
17171818 // mockedA is not called because mockedB is restored to be undefined
1919- expect(mockedA).toHaveBeenCalledTimes(1)
1919+ expect(mockedA).toHaveBeenCalledTimes(0)
2020 expect(mockedB).toHaveBeenCalledTimes(1)
2121})
···496496497497 /**
498498 * Will call `.mockClear()` on all spies before each test
499499- * @default false
499499+ * @default true
500500 */
501501 clearMocks?: boolean
502502