From 9a0002be7c372a0a379a20ef50af100376f7d3eb Mon Sep 17 00:00:00 2001 From: Cue Date: Sat, 11 Feb 2023 12:47:57 +0000 Subject: [PATCH] docs: fix broken links (#2739) --- docs/api/index.md | 4 ++-- docs/api/vi.md | 8 ++++---- docs/config/index.md | 10 +++++----- docs/guide/features.md | 2 +- docs/guide/migration.md | 2 +- docs/guide/mocking.md | 20 ++++++++++---------- docs/guide/snapshot.md | 4 ++-- docs/guide/testing-types.md | 2 +- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/api/index.md b/docs/api/index.md index b593c8738..69d363a26 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -19,7 +19,7 @@ interface TestOptions { When a test function returns a promise, the runner will wait until it is resolved to collect async expectations. If the promise is rejected, the test will fail. ::: tip -In Jest, `TestFunction` can also be of type `(done: DoneCallback) => void`. If this form is used, the test will not be concluded until `done` is called. You can achieve the same using an `async` function, see the [Migration guide Done Callback section](../guide/migration#done-callback). +In Jest, `TestFunction` can also be of type `(done: DoneCallback) => void`. If this form is used, the test will not be concluded until `done` is called. You can achieve the same using an `async` function, see the [Migration guide Done Callback section](/guide/migration#done-callback). ::: ## test @@ -81,7 +81,7 @@ You cannot use this syntax, when using Vitest as [type checker](/guide/testing-t - **Type:** `(condition: any) => Test` - **Alias:** `it.runIf` - Opposite of [test.skipIf](#testskipif). + Opposite of [test.skipIf](#test-skipif). ```ts import { assert, test } from 'vitest' diff --git a/docs/api/vi.md b/docs/api/vi.md index f0b72ffa2..8c48ed880 100644 --- a/docs/api/vi.md +++ b/docs/api/vi.md @@ -70,7 +70,7 @@ import { vi } from 'vitest' ## vi.clearAllMocks - Will call [`.mockClear()`](/api/mock.html#mockclear) on all spies. This will clear mock history, but not reset its implementation to the default one. + Will call [`.mockClear()`](/api/mock#mockclear) on all spies. This will clear mock history, but not reset its implementation to the default one. ## vi.clearAllTimers @@ -84,7 +84,7 @@ import { vi } from 'vitest' - **Type:** `(fn?: Function) => CallableMockInstance` - Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](#mockinstance-methods). + Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](/api/mock). If no function is given, mock will return `undefined`, when invoked. ```ts @@ -281,7 +281,7 @@ test('importing the next module imports mocked one', () => { ## vi.resetAllMocks - Will call [`.mockReset()`](/api/mock.html#mockreset) on all spies. This will clear mock history and reset its implementation to an empty function (will return `undefined`). + Will call [`.mockReset()`](/api/mock#mockreset) on all spies. This will clear mock history and reset its implementation to an empty function (will return `undefined`). ## vi.resetConfig @@ -320,7 +320,7 @@ Does not reset mocks registry. To clear mocks registry, use [`vi.unmock`](#vi-un ## vi.restoreAllMocks - Will call [`.mockRestore()`](/api/mock.html#mockrestore) on all spies. This will clear mock history and reset its implementation to the original one. + Will call [`.mockRestore()`](/api/mock#mockrestore) on all spies. This will clear mock history and reset its implementation to the original one. ## vi.restoreCurrentDate diff --git a/docs/config/index.md b/docs/config/index.md index 7ee772b95..679dfdf35 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -906,21 +906,21 @@ Listen to port and serve API. When set to true, the default port is 51204 - **Type:** `boolean` - **Default:** `false` -Will call [`.mockClear()`](/api/#mockclear) on all spies before each test. This will clear mock history, but not reset its implementation to the default one. +Will call [`.mockClear()`](/api/mock#mockclear) on all spies before each test. This will clear mock history, but not reset its implementation to the default one. ### mockReset - **Type:** `boolean` - **Default:** `false` -Will call [`.mockReset()`](/api/#mockreset) on all spies before each test. This will clear mock history and reset its implementation to an empty function (will return `undefined`). +Will call [`.mockReset()`](/api/mock#mockreset) on all spies before each test. This will clear mock history and reset its implementation to an empty function (will return `undefined`). ### restoreMocks - **Type:** `boolean` - **Default:** `false` -Will call [`.mockRestore()`](/api/#mockrestore) on all spies before each test. This will clear mock history and reset its implementation to the original one. +Will call [`.mockRestore()`](/api/mock#mockrestore) on all spies before each test. This will clear mock history and reset its implementation to the original one. ### unstubEnvs @@ -928,7 +928,7 @@ Will call [`.mockRestore()`](/api/#mockrestore) on all spies before each test. T - **Default:** `false` - **Version:** Since Vitest 0.26.0 -Will call [`vi.unstubAllEnvs`](/api/#vi-unstuballenvs) before each test. +Will call [`vi.unstubAllEnvs`](/api/vi#vi-unstuballenvs) before each test. ### unstubGlobals @@ -936,7 +936,7 @@ Will call [`vi.unstubAllEnvs`](/api/#vi-unstuballenvs) before each test. - **Default:** `false` - **Version:** Since Vitest 0.26.0 -Will call [`vi.unstubAllGlobals`](/api/#vi-unstuballglobals) before each test. +Will call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals) before each test. ### transformMode diff --git a/docs/guide/features.md b/docs/guide/features.md index 0e5871939..9c48626fd 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -70,7 +70,7 @@ describe.concurrent('suite', () => { }) ``` -You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](../api/#concurrent). +You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](/api/#test-concurrent). ## Snapshot diff --git a/docs/guide/migration.md b/docs/guide/migration.md index 89b76c4d6..4a11d30c7 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -25,7 +25,7 @@ When mocking a module in Jest, the factory argument's return value is the defaul + }) ``` -For more details please refer to the [vi.mock api](/api/#vi-mock) +For more details please refer to the [`vi.mock` api section](/api/vi#vi-mock). **Auto-Mocking Behaviour** diff --git a/docs/guide/mocking.md b/docs/guide/mocking.md index d6ca65788..ad0d5e12b 100644 --- a/docs/guide/mocking.md +++ b/docs/guide/mocking.md @@ -7,14 +7,14 @@ title: Mocking | Guide When writing tests it's only a matter of time before you need to create a "fake" version of an internal — or external — service. This is commonly referred to as **mocking**. Vitest provides utility functions to help you out through its **vi** helper. You can `import { vi } from 'vitest'` or access it **globally** (when [global configuration](/config/#globals) is **enabled**). ::: warning -Always remember to clear or restore mocks before or after each test run to undo mock state changes between runs! See [`mockReset`](/api/#mockreset) docs for more info. +Always remember to clear or restore mocks before or after each test run to undo mock state changes between runs! See [`mockReset`](/api/mock#mockreset) docs for more info. ::: -If you wanna dive in head first, check out the [API section](/api/#vi) otherwise keep reading to take a deeper dive into the world of mocking. +If you wanna dive in head first, check out the [API section](/api/vi) otherwise keep reading to take a deeper dive into the world of mocking. ## Dates -Sometimes you need to be in control of the date to ensure consistency when testing. Vitest uses [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers) package for manipulating timers, as well as system date. You can find more about the specific API in detail [here](/api/#vi-setsystemtime). +Sometimes you need to be in control of the date to ensure consistency when testing. Vitest uses [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers) package for manipulating timers, as well as system date. You can find more about the specific API in detail [here](/api/vi#vi-setsystemtime). ### Example @@ -68,9 +68,9 @@ describe('purchasing flow', () => { Mocking functions can be split up into two different categories; *spying & mocking*. -Sometimes all you need is to validate whether or not a specific function has been called (and possibly which arguments were passed). In these cases a spy would be all we need which you can use directly with `vi.spyOn()` ([read more here](/api/#vi-spyon)). +Sometimes all you need is to validate whether or not a specific function has been called (and possibly which arguments were passed). In these cases a spy would be all we need which you can use directly with `vi.spyOn()` ([read more here](/api/vi#vi-spyon)). -However spies can only help you **spy** on functions, they are not able to alter the implementation of those functions. In the case where we do need to create a fake (or mocked) version of a function we can use `vi.fn()` ([read more here](/api/#vi-fn)). +However spies can only help you **spy** on functions, they are not able to alter the implementation of those functions. In the case where we do need to create a fake (or mocked) version of a function we can use `vi.fn()` ([read more here](/api/vi#vi-fn)). We use [Tinyspy](https://github.com/tinylibs/tinyspy) as a base for mocking functions, but we have our own wrapper to make it `jest` compatible. Both `vi.fn()` and `vi.spyOn()` share the same methods, however only the return result of `vi.fn()` is callable. @@ -133,7 +133,7 @@ describe('reading messages', () => { ## Globals -You can mock global variables that are not present with `jsdom` or `node` by using [`vi.stubGlobal`](/api/#vi-stubglobal) helper. It will put the value of the global variable into a `globalThis` object. +You can mock global variables that are not present with `jsdom` or `node` by using [`vi.stubGlobal`](/api/vi#vi-stubglobal) helper. It will put the value of the global variable into a `globalThis` object. ```ts import { vi } from 'vitest' @@ -154,7 +154,7 @@ vi.stubGlobal('IntersectionObserver', IntersectionObserverMock) Mock modules observe third-party-libraries, that are invoked in some other code, allowing you to test arguments, output or even redeclare its implementation. -See the [`vi.mock()` api section](/api/#vi-mock) for a more in-depth detailed API description. +See the [`vi.mock()` api section](/api/vi#vi-mock) for a more in-depth detailed API description. ### Automocking algorithm @@ -324,7 +324,7 @@ There is much more to MSW. You can access cookies and query parameters, define m Whenever we test code that involves timeouts or intervals, instead of having our tests wait it out or timeout. We can speed up our tests by using "fake" timers by mocking calls to `setTimeout` and `setInterval`, too. -See the [`vi.useFakeTimers` api section](/api/#vi-usefaketimers) for a more in depth detailed API description. +See the [`vi.useFakeTimers` api section](/api/vi#vi-usefaketimers) for a more in depth detailed API description. ### Example @@ -530,7 +530,7 @@ vi.useRealTimers() - Mock global variable -You can set global variable by assigning a value to `globalThis` or using [`vi.stubGlobal`](/api/#vi-stubglobal) helper. When using `vi.stubGlobal`, it will **not** automatically reset between different tests, unless you enable [`unstubGlobals`](/config/#unstubglobals) config option or call [`vi.unstubAllGlobals`](/api/#vi-unstuballglobals). +You can set global variable by assigning a value to `globalThis` or using [`vi.stubGlobal`](/api/vi#vi-stubglobal) helper. When using `vi.stubGlobal`, it will **not** automatically reset between different tests, unless you enable [`unstubGlobals`](/config/#unstubglobals) config option or call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals). ```ts vi.stubGlobal('__VERSION__', '1.0.0') @@ -557,7 +557,7 @@ it('changes value', () => { }) ``` -If you want to automatically reset value, you can use `vi.stubEnv` helper with [`unstubEnvs`](/config/#unstubEnvs) config option enabled (or call [`vi.unstubAllEnvs`](/api/#vi-unstuballenvs) manually in `beforeEach` hook): +If you want to automatically reset value, you can use `vi.stubEnv` helper with [`unstubEnvs`](/config/#unstubEnvs) config option enabled (or call [`vi.unstubAllEnvs`](/api/vi#vi-unstuballenvs) manually in `beforeEach` hook): ```ts import { expect, it, vi } from 'vitest' diff --git a/docs/guide/snapshot.md b/docs/guide/snapshot.md index 99a02580a..b4e1b3297 100644 --- a/docs/guide/snapshot.md +++ b/docs/guide/snapshot.md @@ -12,7 +12,7 @@ When using snapshot, Vitest will take a snapshot of the given value, then compar ## Use Snapshots -To snapshot a value, you can use the [`toMatchSnapshot()`](/api/#tomatchsnapshot) from `expect()` API: +To snapshot a value, you can use the [`toMatchSnapshot()`](/api/expect#tomatchsnapshot) from `expect()` API: ```ts import { expect, it } from 'vitest' @@ -35,7 +35,7 @@ The snapshot artifact should be committed alongside code changes, and reviewed a ## Inline Snapshots -Similarly, you can use the [`toMatchInlineSnapshot()`](/api/#tomatchinlinesnapshot) to store the snapshot inline within the test file. +Similarly, you can use the [`toMatchInlineSnapshot()`](/api/expect#tomatchinlinesnapshot) to store the snapshot inline within the test file. ```ts import { expect, it } from 'vitest' diff --git a/docs/guide/testing-types.md b/docs/guide/testing-types.md index 35340ea89..fedb5d95f 100644 --- a/docs/guide/testing-types.md +++ b/docs/guide/testing-types.md @@ -27,7 +27,7 @@ test('my types work properly', () => { Any type error triggered inside a test file will be treated as a test error, so you can use any type trick you want to test types of your project. -You can see a list of possible matchers in [API section](/api/#expecttypeof). +You can see a list of possible matchers in [API section](/api/expect-typeof). ## Reading Errors -- 2.51.2