@vitest-agent/mcp 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/bin/vitest-agent-mcp.js +1 -17
- package/index.d.ts +324 -315
- package/index.js +2 -4
- package/middleware/idempotency.js +1 -1
- package/package.json +2 -2
- package/server.js +2 -4
- package/tools/acceptance-metrics.js +1 -1
- package/tools/cache-health.js +1 -1
- package/tools/commit-changes.js +1 -1
- package/tools/configure.js +1 -1
- package/tools/coverage.js +1 -1
- package/tools/errors.js +1 -1
- package/tools/failure-signature-get.js +1 -1
- package/tools/file-coverage.js +1 -1
- package/tools/history.js +1 -1
- package/tools/inventory.js +1 -1
- package/tools/overview.js +1 -1
- package/tools/run-tests.js +15 -3
- package/tools/settings-list.js +1 -1
- package/tools/status.js +1 -1
- package/tools/tdd-artifact.js +1 -1
- package/tools/tdd-task.js +1 -1
- package/tools/test.js +1 -1
- package/tools/trends.js +1 -1
- package/tools/turn-search.js +1 -1
- package/public/patterns/_meta.json +0 -67
- package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
- package/public/patterns/known-issues-and-caveats.md +0 -52
- package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
- package/public/patterns/running-tests-via-mcp.md +0 -58
- package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
- package/public/patterns/testing-effect-schema-definitions.md +0 -71
- package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
- package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
- package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
- package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
- package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
- package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
- package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
- package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
- package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
- package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
- package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
- package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
- package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
- package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
- package/public/vendor/vitest-docs/api/assert-type.md +0 -22
- package/public/vendor/vitest-docs/api/assert.md +0 -1960
- package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
- package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
- package/public/vendor/vitest-docs/api/browser/context.md +0 -338
- package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
- package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
- package/public/vendor/vitest-docs/api/browser/react.md +0 -346
- package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
- package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
- package/public/vendor/vitest-docs/api/describe.md +0 -374
- package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
- package/public/vendor/vitest-docs/api/expect.md +0 -2304
- package/public/vendor/vitest-docs/api/hooks.md +0 -463
- package/public/vendor/vitest-docs/api/mock.md +0 -701
- package/public/vendor/vitest-docs/api/test.md +0 -926
- package/public/vendor/vitest-docs/api/vi.md +0 -1372
- package/public/vendor/vitest-docs/config/alias.md +0 -13
- package/public/vendor/vitest-docs/config/allowonly.md +0 -32
- package/public/vendor/vitest-docs/config/api.md +0 -27
- package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
- package/public/vendor/vitest-docs/config/bail.md +0 -9
- package/public/vendor/vitest-docs/config/benchmark.md +0 -65
- package/public/vendor/vitest-docs/config/browser/api.md +0 -23
- package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
- package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
- package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
- package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
- package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
- package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
- package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
- package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
- package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
- package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
- package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
- package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
- package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
- package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
- package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
- package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
- package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
- package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
- package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
- package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
- package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
- package/public/vendor/vitest-docs/config/cache.md +0 -26
- package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
- package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
- package/public/vendor/vitest-docs/config/coverage.md +0 -455
- package/public/vendor/vitest-docs/config/css.md +0 -47
- package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
- package/public/vendor/vitest-docs/config/deps.md +0 -127
- package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
- package/public/vendor/vitest-docs/config/diff.md +0 -96
- package/public/vendor/vitest-docs/config/dir.md +0 -7
- package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
- package/public/vendor/vitest-docs/config/env.md +0 -5
- package/public/vendor/vitest-docs/config/environment.md +0 -96
- package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
- package/public/vendor/vitest-docs/config/exclude.md +0 -49
- package/public/vendor/vitest-docs/config/execargv.md +0 -10
- package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
- package/public/vendor/vitest-docs/config/expect.md +0 -38
- package/public/vendor/vitest-docs/config/experimental.md +0 -510
- package/public/vendor/vitest-docs/config/faketimers.md +0 -51
- package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
- package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
- package/public/vendor/vitest-docs/config/globals.md +0 -42
- package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
- package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
- package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
- package/public/vendor/vitest-docs/config/include-source.md +0 -115
- package/public/vendor/vitest-docs/config/include.md +0 -71
- package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
- package/public/vendor/vitest-docs/config/index.md +0 -85
- package/public/vendor/vitest-docs/config/isolate.md +0 -13
- package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
- package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
- package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
- package/public/vendor/vitest-docs/config/mockreset.md +0 -22
- package/public/vendor/vitest-docs/config/mode.md +0 -7
- package/public/vendor/vitest-docs/config/name.md +0 -111
- package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
- package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
- package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
- package/public/vendor/vitest-docs/config/open.md +0 -7
- package/public/vendor/vitest-docs/config/outputfile.md +0 -7
- package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
- package/public/vendor/vitest-docs/config/pool.md +0 -45
- package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
- package/public/vendor/vitest-docs/config/projects.md +0 -6
- package/public/vendor/vitest-docs/config/provide.md +0 -45
- package/public/vendor/vitest-docs/config/reporters.md +0 -69
- package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
- package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
- package/public/vendor/vitest-docs/config/retry.md +0 -140
- package/public/vendor/vitest-docs/config/root.md +0 -6
- package/public/vendor/vitest-docs/config/runner.md +0 -6
- package/public/vendor/vitest-docs/config/sequence.md +0 -158
- package/public/vendor/vitest-docs/config/server.md +0 -68
- package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
- package/public/vendor/vitest-docs/config/silent.md +0 -9
- package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
- package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
- package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
- package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
- package/public/vendor/vitest-docs/config/stricttags.md +0 -30
- package/public/vendor/vitest-docs/config/tags.md +0 -141
- package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
- package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
- package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
- package/public/vendor/vitest-docs/config/typecheck.md +0 -77
- package/public/vendor/vitest-docs/config/ui.md +0 -15
- package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
- package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
- package/public/vendor/vitest-docs/config/update.md +0 -16
- package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
- package/public/vendor/vitest-docs/config/watch.md +0 -11
- package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
- package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
- package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
- package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
- package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
- package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
- package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
- package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
- package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
- package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
- package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
- package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
- package/public/vendor/vitest-docs/guide/cli.md +0 -234
- package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
- package/public/vendor/vitest-docs/guide/coverage.md +0 -515
- package/public/vendor/vitest-docs/guide/debugging.md +0 -127
- package/public/vendor/vitest-docs/guide/environment.md +0 -101
- package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
- package/public/vendor/vitest-docs/guide/features.md +0 -310
- package/public/vendor/vitest-docs/guide/filtering.md +0 -175
- package/public/vendor/vitest-docs/guide/ide.md +0 -43
- package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
- package/public/vendor/vitest-docs/guide/in-source.md +0 -159
- package/public/vendor/vitest-docs/guide/index.md +0 -128
- package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
- package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
- package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
- package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
- package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
- package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
- package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
- package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
- package/public/vendor/vitest-docs/guide/migration.md +0 -863
- package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
- package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
- package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
- package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
- package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
- package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
- package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
- package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
- package/public/vendor/vitest-docs/guide/mocking.md +0 -239
- package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
- package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
- package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
- package/public/vendor/vitest-docs/guide/projects.md +0 -291
- package/public/vendor/vitest-docs/guide/recipes.md +0 -59
- package/public/vendor/vitest-docs/guide/reporters.md +0 -723
- package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
- package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
- package/public/vendor/vitest-docs/guide/test-context.md +0 -902
- package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
- package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
- package/public/vendor/vitest-docs/guide/ui.md +0 -160
- package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
- package/public/vendor/vitest-docs/manifest.json +0 -1691
- package/resources/index.js +0 -166
- package/resources/indexes.js +0 -77
- package/resources/manifest-schema.js +0 -46
- package/resources/paths.js +0 -20
- package/resources/patterns.js +0 -22
- package/resources/upstream-docs.js +0 -22
|
@@ -1,571 +0,0 @@
|
|
|
1
|
-
# expectTypeOf
|
|
2
|
-
|
|
3
|
-
::: warning
|
|
4
|
-
During runtime this function doesn't do anything. To [enable typechecking](/guide/testing-types#run-typechecking), don't forget to pass down `--typecheck` flag.
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
- **Type:** `<T>(a: unknown) => ExpectTypeOf`
|
|
8
|
-
|
|
9
|
-
## not
|
|
10
|
-
|
|
11
|
-
- **Type:** `ExpectTypeOf`
|
|
12
|
-
|
|
13
|
-
You can negate all assertions, using `.not` property.
|
|
14
|
-
|
|
15
|
-
## toEqualTypeOf
|
|
16
|
-
|
|
17
|
-
- **Type:** `<T>(expected: T) => void`
|
|
18
|
-
|
|
19
|
-
This matcher will check if the types are fully equal to each other. This matcher will not fail if two objects have different values, but the same type. It will fail however if an object is missing a property.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import { expectTypeOf } from 'vitest'
|
|
23
|
-
|
|
24
|
-
expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
25
|
-
expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
26
|
-
expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
27
|
-
expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## toMatchTypeOf
|
|
31
|
-
|
|
32
|
-
- **Type:** `<T>(expected: T) => void`
|
|
33
|
-
|
|
34
|
-
::: warning DEPRECATED
|
|
35
|
-
This matcher has been deprecated since expect-type v1.2.0. Use [`toExtend`](#toextend) instead.
|
|
36
|
-
:::
|
|
37
|
-
This matcher checks if expect type extends provided type. It is different from `toEqual` and is more similar to [expect's](/api/expect) `toMatchObject()`. With this matcher, you can check if an object “matches” a type.
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import { expectTypeOf } from 'vitest'
|
|
41
|
-
|
|
42
|
-
expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 })
|
|
43
|
-
expectTypeOf<number>().toMatchTypeOf<string | number>()
|
|
44
|
-
expectTypeOf<string | number>().not.toMatchTypeOf<number>()
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## toExtend
|
|
48
|
-
|
|
49
|
-
- **Type:** `<T>(expected: T) => void`
|
|
50
|
-
|
|
51
|
-
This matcher checks if expect type extends provided type. It is different from `toEqual` and is more similar to [expect's](/api/expect) `toMatchObject()`. With this matcher, you can check if an object "matches" a type.
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
import { expectTypeOf } from 'vitest'
|
|
55
|
-
|
|
56
|
-
expectTypeOf({ a: 1, b: 1 }).toExtend({ a: 1 })
|
|
57
|
-
expectTypeOf<number>().toExtend<string | number>()
|
|
58
|
-
expectTypeOf<string | number>().not.toExtend<number>()
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## toMatchObjectType
|
|
62
|
-
|
|
63
|
-
- **Type:** `() => void`
|
|
64
|
-
|
|
65
|
-
This matcher performs a strict check on object types, ensuring that the expected type matches the provided object type. It's stricter than [`toExtend`](#toextend) and is the recommended choice when working with object types as it's more likely to catch issues like readonly properties.
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { expectTypeOf } from 'vitest'
|
|
69
|
-
|
|
70
|
-
expectTypeOf({ a: 1, b: 2 }).toMatchObjectType<{ a: number }>() // preferred
|
|
71
|
-
expectTypeOf({ a: 1, b: 2 }).toExtend<{ a: number }>() // works but less strict
|
|
72
|
-
|
|
73
|
-
// Supports nested object checking
|
|
74
|
-
const user = {
|
|
75
|
-
name: 'John',
|
|
76
|
-
address: { city: 'New York', zip: '10001' }
|
|
77
|
-
}
|
|
78
|
-
expectTypeOf(user).toMatchObjectType<{ name: string; address: { city: string } }>()
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
::: warning
|
|
82
|
-
This matcher only works with plain object types. It will fail for union types and other complex types. For those cases, use [`toExtend`](#toextend) instead.
|
|
83
|
-
:::
|
|
84
|
-
|
|
85
|
-
## extract
|
|
86
|
-
|
|
87
|
-
- **Type:** `ExpectTypeOf<ExtractedUnion>`
|
|
88
|
-
|
|
89
|
-
You can use `.extract` to narrow down types for further testing.
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { expectTypeOf } from 'vitest'
|
|
93
|
-
|
|
94
|
-
type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
|
95
|
-
|
|
96
|
-
interface CSSProperties { margin?: string; padding?: string }
|
|
97
|
-
|
|
98
|
-
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
|
99
|
-
return {}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
|
103
|
-
|
|
104
|
-
expectTypeOf(getResponsiveProp(cssProperties))
|
|
105
|
-
.extract<{ xs?: any }>() // extracts the last type from a union
|
|
106
|
-
.toEqualTypeOf<{ xs?: CSSProperties; sm?: CSSProperties; md?: CSSProperties }>()
|
|
107
|
-
|
|
108
|
-
expectTypeOf(getResponsiveProp(cssProperties))
|
|
109
|
-
.extract<unknown[]>() // extracts an array from a union
|
|
110
|
-
.toEqualTypeOf<CSSProperties[]>()
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
::: warning
|
|
114
|
-
If no type is found in the union, `.extract` will return `never`.
|
|
115
|
-
:::
|
|
116
|
-
|
|
117
|
-
## exclude
|
|
118
|
-
|
|
119
|
-
- **Type:** `ExpectTypeOf<NonExcludedUnion>`
|
|
120
|
-
|
|
121
|
-
You can use `.exclude` to remove types from a union for further testing.
|
|
122
|
-
|
|
123
|
-
```ts
|
|
124
|
-
import { expectTypeOf } from 'vitest'
|
|
125
|
-
|
|
126
|
-
type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
|
127
|
-
|
|
128
|
-
interface CSSProperties { margin?: string; padding?: string }
|
|
129
|
-
|
|
130
|
-
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
|
131
|
-
return {}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
|
135
|
-
|
|
136
|
-
expectTypeOf(getResponsiveProp(cssProperties))
|
|
137
|
-
.exclude<unknown[]>()
|
|
138
|
-
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
|
|
139
|
-
.toEqualTypeOf<CSSProperties>()
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
::: warning
|
|
143
|
-
If no type is found in the union, `.exclude` will return `never`.
|
|
144
|
-
:::
|
|
145
|
-
|
|
146
|
-
## returns
|
|
147
|
-
|
|
148
|
-
- **Type:** `ExpectTypeOf<ReturnValue>`
|
|
149
|
-
|
|
150
|
-
You can use `.returns` to extract return value of a function type.
|
|
151
|
-
|
|
152
|
-
```ts
|
|
153
|
-
import { expectTypeOf } from 'vitest'
|
|
154
|
-
|
|
155
|
-
expectTypeOf(() => {}).returns.toBeVoid()
|
|
156
|
-
expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2])
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
::: warning
|
|
160
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
161
|
-
:::
|
|
162
|
-
|
|
163
|
-
## parameters
|
|
164
|
-
|
|
165
|
-
- **Type:** `ExpectTypeOf<Parameters>`
|
|
166
|
-
|
|
167
|
-
You can extract function arguments with `.parameters` to perform assertions on its value. Parameters are returned as an array.
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
import { expectTypeOf } from 'vitest'
|
|
171
|
-
|
|
172
|
-
type NoParam = () => void
|
|
173
|
-
type HasParam = (s: string) => void
|
|
174
|
-
|
|
175
|
-
expectTypeOf<NoParam>().parameters.toEqualTypeOf<[]>()
|
|
176
|
-
expectTypeOf<HasParam>().parameters.toEqualTypeOf<[string]>()
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
::: warning
|
|
180
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
181
|
-
:::
|
|
182
|
-
|
|
183
|
-
::: tip
|
|
184
|
-
You can also use [`.toBeCallableWith`](#tobecallablewith) matcher as a more expressive assertion.
|
|
185
|
-
:::
|
|
186
|
-
|
|
187
|
-
## parameter
|
|
188
|
-
|
|
189
|
-
- **Type:** `(nth: number) => ExpectTypeOf`
|
|
190
|
-
|
|
191
|
-
You can extract a certain function argument with `.parameter(number)` call to perform other assertions on it.
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
import { expectTypeOf } from 'vitest'
|
|
195
|
-
|
|
196
|
-
function foo(a: number, b: string) {
|
|
197
|
-
return [a, b]
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
expectTypeOf(foo).parameter(0).toBeNumber()
|
|
201
|
-
expectTypeOf(foo).parameter(1).toBeString()
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
::: warning
|
|
205
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
206
|
-
:::
|
|
207
|
-
|
|
208
|
-
## constructorParameters
|
|
209
|
-
|
|
210
|
-
- **Type:** `ExpectTypeOf<ConstructorParameters>`
|
|
211
|
-
|
|
212
|
-
You can extract constructor parameters as an array of values and perform assertions on them with this method.
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
import { expectTypeOf } from 'vitest'
|
|
216
|
-
|
|
217
|
-
expectTypeOf(Date).constructorParameters.toEqualTypeOf<[] | [string | number | Date]>()
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
::: warning
|
|
221
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
222
|
-
:::
|
|
223
|
-
|
|
224
|
-
::: tip
|
|
225
|
-
You can also use [`.toBeConstructibleWith`](#tobeconstructiblewith) matcher as a more expressive assertion.
|
|
226
|
-
:::
|
|
227
|
-
|
|
228
|
-
## instance
|
|
229
|
-
|
|
230
|
-
- **Type:** `ExpectTypeOf<ConstructableInstance>`
|
|
231
|
-
|
|
232
|
-
This property gives access to matchers that can be performed on an instance of the provided class.
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
import { expectTypeOf } from 'vitest'
|
|
236
|
-
|
|
237
|
-
expectTypeOf(Date).instance.toHaveProperty('toISOString')
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
::: warning
|
|
241
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
242
|
-
:::
|
|
243
|
-
|
|
244
|
-
## items
|
|
245
|
-
|
|
246
|
-
- **Type:** `ExpectTypeOf<T>`
|
|
247
|
-
|
|
248
|
-
You can get array item type with `.items` to perform further assertions.
|
|
249
|
-
|
|
250
|
-
```ts
|
|
251
|
-
import { expectTypeOf } from 'vitest'
|
|
252
|
-
|
|
253
|
-
expectTypeOf([1, 2, 3]).items.toEqualTypeOf<number>()
|
|
254
|
-
expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf<string>()
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## resolves
|
|
258
|
-
|
|
259
|
-
- **Type:** `ExpectTypeOf<ResolvedPromise>`
|
|
260
|
-
|
|
261
|
-
This matcher extracts resolved value of a `Promise`, so you can perform other assertions on it.
|
|
262
|
-
|
|
263
|
-
```ts
|
|
264
|
-
import { expectTypeOf } from 'vitest'
|
|
265
|
-
|
|
266
|
-
async function asyncFunc() {
|
|
267
|
-
return 123
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
expectTypeOf(asyncFunc).returns.resolves.toBeNumber()
|
|
271
|
-
expectTypeOf(Promise.resolve('string')).resolves.toBeString()
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
::: warning
|
|
275
|
-
If used on a non-promise type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
276
|
-
:::
|
|
277
|
-
|
|
278
|
-
## guards
|
|
279
|
-
|
|
280
|
-
- **Type:** `ExpectTypeOf<Guard>`
|
|
281
|
-
|
|
282
|
-
This matcher extracts guard value (e.g., `v is number`), so you can perform assertions on it.
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
import { expectTypeOf } from 'vitest'
|
|
286
|
-
|
|
287
|
-
function isString(v: any): v is string {
|
|
288
|
-
return typeof v === 'string'
|
|
289
|
-
}
|
|
290
|
-
expectTypeOf(isString).guards.toBeString()
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
::: warning
|
|
294
|
-
Returns `never`, if the value is not a guard function, so you won't be able to chain it with other matchers.
|
|
295
|
-
:::
|
|
296
|
-
|
|
297
|
-
## asserts
|
|
298
|
-
|
|
299
|
-
- **Type:** `ExpectTypeOf<Assert>`
|
|
300
|
-
|
|
301
|
-
This matcher extracts assert value (e.g., `assert v is number`), so you can perform assertions on it.
|
|
302
|
-
|
|
303
|
-
```ts
|
|
304
|
-
import { expectTypeOf } from 'vitest'
|
|
305
|
-
|
|
306
|
-
function assertNumber(v: any): asserts v is number {
|
|
307
|
-
if (typeof v !== 'number') {
|
|
308
|
-
throw new TypeError('Nope !')
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
expectTypeOf(assertNumber).asserts.toBeNumber()
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
::: warning
|
|
316
|
-
Returns `never`, if the value is not an assert function, so you won't be able to chain it with other matchers.
|
|
317
|
-
:::
|
|
318
|
-
|
|
319
|
-
## toBeAny
|
|
320
|
-
|
|
321
|
-
- **Type:** `() => void`
|
|
322
|
-
|
|
323
|
-
With this matcher you can check, if provided type is `any` type. If the type is too specific, the test will fail.
|
|
324
|
-
|
|
325
|
-
```ts
|
|
326
|
-
import { expectTypeOf } from 'vitest'
|
|
327
|
-
|
|
328
|
-
expectTypeOf<any>().toBeAny()
|
|
329
|
-
expectTypeOf({} as any).toBeAny()
|
|
330
|
-
expectTypeOf('string').not.toBeAny()
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
## toBeUnknown
|
|
334
|
-
|
|
335
|
-
- **Type:** `() => void`
|
|
336
|
-
|
|
337
|
-
This matcher checks, if provided type is `unknown` type.
|
|
338
|
-
|
|
339
|
-
```ts
|
|
340
|
-
import { expectTypeOf } from 'vitest'
|
|
341
|
-
|
|
342
|
-
expectTypeOf().toBeUnknown()
|
|
343
|
-
expectTypeOf({} as unknown).toBeUnknown()
|
|
344
|
-
expectTypeOf('string').not.toBeUnknown()
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## toBeNever
|
|
348
|
-
|
|
349
|
-
- **Type:** `() => void`
|
|
350
|
-
|
|
351
|
-
This matcher checks, if provided type is a `never` type.
|
|
352
|
-
|
|
353
|
-
```ts
|
|
354
|
-
import { expectTypeOf } from 'vitest'
|
|
355
|
-
|
|
356
|
-
expectTypeOf<never>().toBeNever()
|
|
357
|
-
expectTypeOf((): never => {}).returns.toBeNever()
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
## toBeFunction
|
|
361
|
-
|
|
362
|
-
- **Type:** `() => void`
|
|
363
|
-
|
|
364
|
-
This matcher checks, if provided type is a `function`.
|
|
365
|
-
|
|
366
|
-
```ts
|
|
367
|
-
import { expectTypeOf } from 'vitest'
|
|
368
|
-
|
|
369
|
-
expectTypeOf(42).not.toBeFunction()
|
|
370
|
-
expectTypeOf((): never => {}).toBeFunction()
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
## toBeObject
|
|
374
|
-
|
|
375
|
-
- **Type:** `() => void`
|
|
376
|
-
|
|
377
|
-
This matcher checks, if provided type is an `object`.
|
|
378
|
-
|
|
379
|
-
```ts
|
|
380
|
-
import { expectTypeOf } from 'vitest'
|
|
381
|
-
|
|
382
|
-
expectTypeOf(42).not.toBeObject()
|
|
383
|
-
expectTypeOf({}).toBeObject()
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
## toBeArray
|
|
387
|
-
|
|
388
|
-
- **Type:** `() => void`
|
|
389
|
-
|
|
390
|
-
This matcher checks, if provided type is `Array<T>`.
|
|
391
|
-
|
|
392
|
-
```ts
|
|
393
|
-
import { expectTypeOf } from 'vitest'
|
|
394
|
-
|
|
395
|
-
expectTypeOf(42).not.toBeArray()
|
|
396
|
-
expectTypeOf([]).toBeArray()
|
|
397
|
-
expectTypeOf([1, 2]).toBeArray()
|
|
398
|
-
expectTypeOf([{}, 42]).toBeArray()
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
## toBeString
|
|
402
|
-
|
|
403
|
-
- **Type:** `() => void`
|
|
404
|
-
|
|
405
|
-
This matcher checks, if provided type is a `string`.
|
|
406
|
-
|
|
407
|
-
```ts
|
|
408
|
-
import { expectTypeOf } from 'vitest'
|
|
409
|
-
|
|
410
|
-
expectTypeOf(42).not.toBeString()
|
|
411
|
-
expectTypeOf('').toBeString()
|
|
412
|
-
expectTypeOf('a').toBeString()
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
## toBeBoolean
|
|
416
|
-
|
|
417
|
-
- **Type:** `() => void`
|
|
418
|
-
|
|
419
|
-
This matcher checks, if provided type is `boolean`.
|
|
420
|
-
|
|
421
|
-
```ts
|
|
422
|
-
import { expectTypeOf } from 'vitest'
|
|
423
|
-
|
|
424
|
-
expectTypeOf(42).not.toBeBoolean()
|
|
425
|
-
expectTypeOf(true).toBeBoolean()
|
|
426
|
-
expectTypeOf<boolean>().toBeBoolean()
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## toBeVoid
|
|
430
|
-
|
|
431
|
-
- **Type:** `() => void`
|
|
432
|
-
|
|
433
|
-
This matcher checks, if provided type is `void`.
|
|
434
|
-
|
|
435
|
-
```ts
|
|
436
|
-
import { expectTypeOf } from 'vitest'
|
|
437
|
-
|
|
438
|
-
expectTypeOf(() => {}).returns.toBeVoid()
|
|
439
|
-
expectTypeOf<void>().toBeVoid()
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
## toBeSymbol
|
|
443
|
-
|
|
444
|
-
- **Type:** `() => void`
|
|
445
|
-
|
|
446
|
-
This matcher checks, if provided type is a `symbol`.
|
|
447
|
-
|
|
448
|
-
```ts
|
|
449
|
-
import { expectTypeOf } from 'vitest'
|
|
450
|
-
|
|
451
|
-
expectTypeOf(Symbol(1)).toBeSymbol()
|
|
452
|
-
expectTypeOf<symbol>().toBeSymbol()
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
## toBeNull
|
|
456
|
-
|
|
457
|
-
- **Type:** `() => void`
|
|
458
|
-
|
|
459
|
-
This matcher checks, if provided type is `null`.
|
|
460
|
-
|
|
461
|
-
```ts
|
|
462
|
-
import { expectTypeOf } from 'vitest'
|
|
463
|
-
|
|
464
|
-
expectTypeOf(null).toBeNull()
|
|
465
|
-
expectTypeOf<null>().toBeNull()
|
|
466
|
-
expectTypeOf(undefined).not.toBeNull()
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
## toBeUndefined
|
|
470
|
-
|
|
471
|
-
- **Type:** `() => void`
|
|
472
|
-
|
|
473
|
-
This matcher checks, if provided type is `undefined`.
|
|
474
|
-
|
|
475
|
-
```ts
|
|
476
|
-
import { expectTypeOf } from 'vitest'
|
|
477
|
-
|
|
478
|
-
expectTypeOf(undefined).toBeUndefined()
|
|
479
|
-
expectTypeOf<undefined>().toBeUndefined()
|
|
480
|
-
expectTypeOf(null).not.toBeUndefined()
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
## toBeNullable
|
|
484
|
-
|
|
485
|
-
- **Type:** `() => void`
|
|
486
|
-
|
|
487
|
-
This matcher checks, if you can use `null` or `undefined` with provided type.
|
|
488
|
-
|
|
489
|
-
```ts
|
|
490
|
-
import { expectTypeOf } from 'vitest'
|
|
491
|
-
|
|
492
|
-
expectTypeOf<undefined | 1>().toBeNullable()
|
|
493
|
-
expectTypeOf<null | 1>().toBeNullable()
|
|
494
|
-
expectTypeOf<undefined | null | 1>().toBeNullable()
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
## toBeCallableWith
|
|
498
|
-
|
|
499
|
-
- **Type:** `() => void`
|
|
500
|
-
|
|
501
|
-
This matcher ensures you can call provided function with a set of parameters.
|
|
502
|
-
|
|
503
|
-
```ts
|
|
504
|
-
import { expectTypeOf } from 'vitest'
|
|
505
|
-
|
|
506
|
-
type NoParam = () => void
|
|
507
|
-
type HasParam = (s: string) => void
|
|
508
|
-
|
|
509
|
-
expectTypeOf<NoParam>().toBeCallableWith()
|
|
510
|
-
expectTypeOf<HasParam>().toBeCallableWith('some string')
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
::: warning
|
|
514
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
515
|
-
:::
|
|
516
|
-
|
|
517
|
-
## toBeConstructibleWith
|
|
518
|
-
|
|
519
|
-
- **Type:** `() => void`
|
|
520
|
-
|
|
521
|
-
This matcher ensures you can create a new instance with a set of constructor parameters.
|
|
522
|
-
|
|
523
|
-
```ts
|
|
524
|
-
import { expectTypeOf } from 'vitest'
|
|
525
|
-
|
|
526
|
-
expectTypeOf(Date).toBeConstructibleWith(new Date())
|
|
527
|
-
expectTypeOf(Date).toBeConstructibleWith('01-01-2000')
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
::: warning
|
|
531
|
-
If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
|
|
532
|
-
:::
|
|
533
|
-
|
|
534
|
-
## toHaveProperty
|
|
535
|
-
|
|
536
|
-
- **Type:** `<K extends keyof T>(property: K) => ExpectTypeOf<T[K>`
|
|
537
|
-
|
|
538
|
-
This matcher checks if a property exists on the provided object. If it exists, it also returns the same set of matchers for the type of this property, so you can chain assertions one after another.
|
|
539
|
-
|
|
540
|
-
```ts
|
|
541
|
-
import { expectTypeOf } from 'vitest'
|
|
542
|
-
|
|
543
|
-
const obj = { a: 1, b: '' }
|
|
544
|
-
|
|
545
|
-
expectTypeOf(obj).toHaveProperty('a')
|
|
546
|
-
expectTypeOf(obj).not.toHaveProperty('c')
|
|
547
|
-
|
|
548
|
-
expectTypeOf(obj).toHaveProperty('a').toBeNumber()
|
|
549
|
-
expectTypeOf(obj).toHaveProperty('b').toBeString()
|
|
550
|
-
expectTypeOf(obj).toHaveProperty('a').not.toBeString()
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
## branded
|
|
554
|
-
|
|
555
|
-
- **Type:** `ExpectTypeOf<BrandedType>`
|
|
556
|
-
|
|
557
|
-
You can use `.branded` to allow type assertions to succeed for types that are semantically equivalent but differ in representation.
|
|
558
|
-
|
|
559
|
-
```ts
|
|
560
|
-
import { expectTypeOf } from 'vitest'
|
|
561
|
-
|
|
562
|
-
// Without .branded, this fails even though the types are effectively the same
|
|
563
|
-
expectTypeOf<{ a: { b: 1 } & { c: 1 } }>().toEqualTypeOf<{ a: { b: 1; c: 1 } }>()
|
|
564
|
-
|
|
565
|
-
// With .branded, the assertion succeeds
|
|
566
|
-
expectTypeOf<{ a: { b: 1 } & { c: 1 } }>().branded.toEqualTypeOf<{ a: { b: 1; c: 1 } }>()
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
::: warning
|
|
570
|
-
This helper comes at a performance cost and can cause the TypeScript compiler to 'give up' if used with excessively deep types. Use it sparingly and only when necessary.
|
|
571
|
-
:::
|