@crab-dev/wake 0.1.21 → 0.1.23
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/CHANGELOG.md +32 -0
- package/bin/terminal.mjs +20 -4
- package/bin/wake.mjs +418 -0
- package/index.cjs +197 -0
- package/index.d.ts +254 -0
- package/index.mjs +3 -0
- package/loader.cjs +19 -2
- package/package.json +32 -12
- package/test-context-internal.cjs +30 -0
- package/test-react.cjs +60 -0
- package/test-react.d.ts +162 -0
- package/test-react.mjs +29 -0
- package/test.cjs +98 -0
- package/test.d.ts +265 -0
- package/test.mjs +15 -0
package/test-react.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const core = require('./test.cjs')
|
|
4
|
+
|
|
5
|
+
function contextError() {
|
|
6
|
+
const error = new Error('@crab-dev/wake/test/react can only be used inside wake test')
|
|
7
|
+
error.name = 'WakeError'
|
|
8
|
+
error.code = 'WAKE_TEST_CONTEXT'
|
|
9
|
+
return error
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function unavailable() {
|
|
13
|
+
throw contextError()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const screenEntries = { debug: unavailable }
|
|
17
|
+
for (const family of [
|
|
18
|
+
'Role',
|
|
19
|
+
'Text',
|
|
20
|
+
'LabelText',
|
|
21
|
+
'DisplayValue',
|
|
22
|
+
'PlaceholderText',
|
|
23
|
+
'AltText',
|
|
24
|
+
'Title',
|
|
25
|
+
'TestId',
|
|
26
|
+
]) {
|
|
27
|
+
for (const prefix of ['getBy', 'getAllBy', 'queryBy', 'queryAllBy', 'findBy', 'findAllBy']) {
|
|
28
|
+
screenEntries[`${prefix}${family}`] = unavailable
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const screen = Object.freeze(screenEntries)
|
|
32
|
+
|
|
33
|
+
const userEvent = Object.freeze({ setup: unavailable })
|
|
34
|
+
|
|
35
|
+
const fireEvent = Object.freeze(Object.assign(
|
|
36
|
+
(...args) => unavailable(...args),
|
|
37
|
+
{
|
|
38
|
+
change: unavailable,
|
|
39
|
+
click: unavailable,
|
|
40
|
+
input: unavailable,
|
|
41
|
+
keyDown: unavailable,
|
|
42
|
+
keyUp: unavailable,
|
|
43
|
+
submit: unavailable,
|
|
44
|
+
},
|
|
45
|
+
))
|
|
46
|
+
|
|
47
|
+
module.exports = Object.freeze({
|
|
48
|
+
...core,
|
|
49
|
+
act: unavailable,
|
|
50
|
+
cleanup: unavailable,
|
|
51
|
+
fireEvent,
|
|
52
|
+
prettyDOM: unavailable,
|
|
53
|
+
render: unavailable,
|
|
54
|
+
renderHook: unavailable,
|
|
55
|
+
screen,
|
|
56
|
+
userEvent,
|
|
57
|
+
waitFor: unavailable,
|
|
58
|
+
waitForElementToBeRemoved: unavailable,
|
|
59
|
+
within: unavailable,
|
|
60
|
+
})
|
package/test-react.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export * from '@crab-dev/wake/test'
|
|
4
|
+
|
|
5
|
+
export interface RenderOptions {
|
|
6
|
+
container?: HTMLElement
|
|
7
|
+
baseElement?: HTMLElement
|
|
8
|
+
hydrate?: boolean
|
|
9
|
+
strict?: boolean
|
|
10
|
+
wrapper?: (props: { children: ReactNode }) => ReactElement
|
|
11
|
+
identifierPrefix?: string
|
|
12
|
+
onCaughtError?: (error: unknown, info: { componentStack: string }) => void
|
|
13
|
+
onUncaughtError?: (error: unknown, info: { componentStack: string }) => void
|
|
14
|
+
onRecoverableError?: (error: unknown, info: { componentStack: string }) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RenderResult {
|
|
18
|
+
readonly container: HTMLElement
|
|
19
|
+
readonly baseElement: HTMLElement
|
|
20
|
+
rerender(ui: ReactElement): Promise<void>
|
|
21
|
+
unmount(): Promise<void>
|
|
22
|
+
asFragment(): DocumentFragment
|
|
23
|
+
debug(element?: Element | DocumentFragment): string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface RenderHookOptions<Props> {
|
|
27
|
+
initialProps?: Props
|
|
28
|
+
wrapper?: (props: { children: ReactNode }) => ReactElement
|
|
29
|
+
strict?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RenderHookResult<Result, Props> {
|
|
33
|
+
readonly result: { readonly current: Result }
|
|
34
|
+
rerender(props?: Props): Promise<void>
|
|
35
|
+
unmount(): Promise<void>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TextMatcher = string | RegExp | ((content: string, element: Element) => boolean)
|
|
39
|
+
|
|
40
|
+
export interface RoleQueryOptions {
|
|
41
|
+
name?: TextMatcher
|
|
42
|
+
description?: TextMatcher
|
|
43
|
+
hidden?: boolean
|
|
44
|
+
selected?: boolean
|
|
45
|
+
checked?: boolean
|
|
46
|
+
pressed?: boolean
|
|
47
|
+
expanded?: boolean
|
|
48
|
+
level?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface QueryOptions {
|
|
52
|
+
exact?: boolean
|
|
53
|
+
timeout?: number
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Queries {
|
|
57
|
+
getByRole(role: string, options?: RoleQueryOptions): HTMLElement
|
|
58
|
+
getAllByRole(role: string, options?: RoleQueryOptions): HTMLElement[]
|
|
59
|
+
queryByRole(role: string, options?: RoleQueryOptions): HTMLElement | null
|
|
60
|
+
queryAllByRole(role: string, options?: RoleQueryOptions): HTMLElement[]
|
|
61
|
+
findByRole(role: string, options?: RoleQueryOptions & QueryOptions): Promise<HTMLElement>
|
|
62
|
+
findAllByRole(role: string, options?: RoleQueryOptions & QueryOptions): Promise<HTMLElement[]>
|
|
63
|
+
getByText(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
64
|
+
getAllByText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
65
|
+
queryByText(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
66
|
+
queryAllByText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
67
|
+
findByText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
68
|
+
findAllByText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
69
|
+
getByLabelText(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
70
|
+
getAllByLabelText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
71
|
+
queryByLabelText(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
72
|
+
queryAllByLabelText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
73
|
+
findByLabelText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
74
|
+
findAllByLabelText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
75
|
+
getByDisplayValue(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
76
|
+
getAllByDisplayValue(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
77
|
+
queryByDisplayValue(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
78
|
+
queryAllByDisplayValue(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
79
|
+
findByDisplayValue(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
80
|
+
findAllByDisplayValue(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
81
|
+
getByPlaceholderText(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
82
|
+
getAllByPlaceholderText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
83
|
+
queryByPlaceholderText(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
84
|
+
queryAllByPlaceholderText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
85
|
+
findByPlaceholderText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
86
|
+
findAllByPlaceholderText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
87
|
+
getByAltText(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
88
|
+
getAllByAltText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
89
|
+
queryByAltText(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
90
|
+
queryAllByAltText(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
91
|
+
findByAltText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
92
|
+
findAllByAltText(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
93
|
+
getByTitle(text: TextMatcher, options?: QueryOptions): HTMLElement
|
|
94
|
+
getAllByTitle(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
95
|
+
queryByTitle(text: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
96
|
+
queryAllByTitle(text: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
97
|
+
findByTitle(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
98
|
+
findAllByTitle(text: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
99
|
+
getByTestId(id: TextMatcher, options?: QueryOptions): HTMLElement
|
|
100
|
+
getAllByTestId(id: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
101
|
+
queryByTestId(id: TextMatcher, options?: QueryOptions): HTMLElement | null
|
|
102
|
+
queryAllByTestId(id: TextMatcher, options?: QueryOptions): HTMLElement[]
|
|
103
|
+
findByTestId(id: TextMatcher, options?: QueryOptions): Promise<HTMLElement>
|
|
104
|
+
findAllByTestId(id: TextMatcher, options?: QueryOptions): Promise<HTMLElement[]>
|
|
105
|
+
debug(element?: Element | DocumentFragment): string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface UserEventOptions {
|
|
109
|
+
delayMs?: number
|
|
110
|
+
document?: Document
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface UserEventController {
|
|
114
|
+
click(element: Element): Promise<void>
|
|
115
|
+
dblClick(element: Element): Promise<void>
|
|
116
|
+
type(element: Element, text: string): Promise<void>
|
|
117
|
+
clear(element: Element): Promise<void>
|
|
118
|
+
keyboard(input: string): Promise<void>
|
|
119
|
+
tab(options?: { shift?: boolean }): Promise<void>
|
|
120
|
+
hover(element: Element): Promise<void>
|
|
121
|
+
unhover(element: Element): Promise<void>
|
|
122
|
+
selectOptions(element: Element, values: string | readonly string[] | Element | readonly Element[]): Promise<void>
|
|
123
|
+
upload(element: HTMLInputElement, files: File | readonly File[]): Promise<void>
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface UserEventApi {
|
|
127
|
+
setup(options?: UserEventOptions): UserEventController
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface FireEventApi {
|
|
131
|
+
(element: Element, event: Event): Promise<boolean>
|
|
132
|
+
change(element: Element, init?: EventInit & { target?: Record<string, unknown> }): Promise<boolean>
|
|
133
|
+
click(element: Element, init?: MouseEventInit): Promise<boolean>
|
|
134
|
+
input(element: Element, init?: InputEventInit & { target?: Record<string, unknown> }): Promise<boolean>
|
|
135
|
+
keyDown(element: Element, init?: KeyboardEventInit): Promise<boolean>
|
|
136
|
+
keyUp(element: Element, init?: KeyboardEventInit): Promise<boolean>
|
|
137
|
+
submit(element: Element, init?: SubmitEventInit): Promise<boolean>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface WaitForOptions {
|
|
141
|
+
container?: HTMLElement
|
|
142
|
+
timeout?: number
|
|
143
|
+
interval?: number
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function render(ui: ReactElement, options?: RenderOptions): Promise<RenderResult>
|
|
147
|
+
export function renderHook<Result, Props = void>(
|
|
148
|
+
callback: (props: Props) => Result,
|
|
149
|
+
options?: RenderHookOptions<Props>,
|
|
150
|
+
): Promise<RenderHookResult<Result, Props>>
|
|
151
|
+
export function cleanup(): Promise<void>
|
|
152
|
+
export function act<T>(callback: () => T | PromiseLike<T>): Promise<Awaited<T>>
|
|
153
|
+
export function waitFor<T>(callback: () => T | PromiseLike<T>, options?: WaitForOptions): Promise<T>
|
|
154
|
+
export function waitForElementToBeRemoved(
|
|
155
|
+
callback: () => Element | readonly Element[] | null,
|
|
156
|
+
options?: WaitForOptions,
|
|
157
|
+
): Promise<void>
|
|
158
|
+
export function prettyDOM(element?: Element | DocumentFragment, maxLength?: number): string
|
|
159
|
+
export function within(element: HTMLElement): Queries
|
|
160
|
+
export const screen: Queries
|
|
161
|
+
export const userEvent: UserEventApi
|
|
162
|
+
export const fireEvent: FireEventApi
|
package/test-react.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import api from './test-react.cjs'
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
afterAll,
|
|
5
|
+
afterEach,
|
|
6
|
+
beforeAll,
|
|
7
|
+
beforeEach,
|
|
8
|
+
clock,
|
|
9
|
+
describe,
|
|
10
|
+
expect,
|
|
11
|
+
it,
|
|
12
|
+
mock,
|
|
13
|
+
network,
|
|
14
|
+
test,
|
|
15
|
+
} from './test.mjs'
|
|
16
|
+
|
|
17
|
+
export const {
|
|
18
|
+
act,
|
|
19
|
+
cleanup,
|
|
20
|
+
fireEvent,
|
|
21
|
+
prettyDOM,
|
|
22
|
+
render,
|
|
23
|
+
renderHook,
|
|
24
|
+
screen,
|
|
25
|
+
userEvent,
|
|
26
|
+
waitFor,
|
|
27
|
+
waitForElementToBeRemoved,
|
|
28
|
+
within,
|
|
29
|
+
} = api
|
package/test.cjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function contextError() {
|
|
4
|
+
const error = new Error('@crab-dev/wake/test can only be used inside wake test')
|
|
5
|
+
error.name = 'WakeError'
|
|
6
|
+
error.code = 'WAKE_TEST_CONTEXT'
|
|
7
|
+
return error
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function unavailable() {
|
|
11
|
+
throw contextError()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function callable(properties) {
|
|
15
|
+
const entry = (...args) => unavailable(...args)
|
|
16
|
+
return Object.freeze(Object.assign(entry, properties))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function testApi() {
|
|
20
|
+
const entry = (...args) => unavailable(...args)
|
|
21
|
+
entry.only = entry
|
|
22
|
+
entry.skip = entry
|
|
23
|
+
entry.todo = unavailable
|
|
24
|
+
entry.each = unavailable
|
|
25
|
+
return Object.freeze(entry)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function describeApi() {
|
|
29
|
+
const entry = (...args) => unavailable(...args)
|
|
30
|
+
entry.only = entry
|
|
31
|
+
entry.skip = entry
|
|
32
|
+
entry.each = unavailable
|
|
33
|
+
return Object.freeze(entry)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const test = testApi()
|
|
37
|
+
const describe = describeApi()
|
|
38
|
+
|
|
39
|
+
const expect = callable({
|
|
40
|
+
extend: unavailable,
|
|
41
|
+
addEqualityTesters: unavailable,
|
|
42
|
+
addSnapshotSerializer: unavailable,
|
|
43
|
+
assertions: unavailable,
|
|
44
|
+
hasAssertions: unavailable,
|
|
45
|
+
getState: unavailable,
|
|
46
|
+
setState: unavailable,
|
|
47
|
+
any: unavailable,
|
|
48
|
+
anything: unavailable,
|
|
49
|
+
arrayContaining: unavailable,
|
|
50
|
+
objectContaining: unavailable,
|
|
51
|
+
stringContaining: unavailable,
|
|
52
|
+
stringMatching: unavailable,
|
|
53
|
+
closeTo: unavailable,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const mock = Object.freeze({
|
|
57
|
+
fn: unavailable,
|
|
58
|
+
spyOn: unavailable,
|
|
59
|
+
replaceProperty: unavailable,
|
|
60
|
+
module: unavailable,
|
|
61
|
+
import: unavailable,
|
|
62
|
+
actual: unavailable,
|
|
63
|
+
isolate: unavailable,
|
|
64
|
+
clearAll: unavailable,
|
|
65
|
+
resetAll: unavailable,
|
|
66
|
+
restoreAll: unavailable,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const clock = Object.freeze({
|
|
70
|
+
fake: unavailable,
|
|
71
|
+
restore: unavailable,
|
|
72
|
+
advanceBy: unavailable,
|
|
73
|
+
advanceTo: unavailable,
|
|
74
|
+
runNext: unavailable,
|
|
75
|
+
runAll: unavailable,
|
|
76
|
+
flushMicrotasks: unavailable,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const network = Object.freeze({
|
|
80
|
+
route: unavailable,
|
|
81
|
+
allow: unavailable,
|
|
82
|
+
requests: unavailable,
|
|
83
|
+
reset: unavailable,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
module.exports = Object.freeze({
|
|
87
|
+
afterAll: unavailable,
|
|
88
|
+
afterEach: unavailable,
|
|
89
|
+
beforeAll: unavailable,
|
|
90
|
+
beforeEach: unavailable,
|
|
91
|
+
clock,
|
|
92
|
+
describe,
|
|
93
|
+
expect,
|
|
94
|
+
it: test,
|
|
95
|
+
mock,
|
|
96
|
+
network,
|
|
97
|
+
test,
|
|
98
|
+
})
|
package/test.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
export type Awaitable<T> = T | PromiseLike<T>
|
|
2
|
+
export type TestCallback = () => Awaitable<void>
|
|
3
|
+
|
|
4
|
+
export interface TestCaseOptions {
|
|
5
|
+
timeout: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Each {
|
|
9
|
+
<T extends readonly unknown[]>(table: readonly T[]): (
|
|
10
|
+
name: string,
|
|
11
|
+
callback: (...values: T) => Awaitable<void>,
|
|
12
|
+
options?: TestCaseOptions,
|
|
13
|
+
) => void
|
|
14
|
+
<T>(table: readonly T[]): (
|
|
15
|
+
name: string,
|
|
16
|
+
callback: (value: T) => Awaitable<void>,
|
|
17
|
+
options?: TestCaseOptions,
|
|
18
|
+
) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TestApi {
|
|
22
|
+
(name: string, callback: TestCallback, options?: TestCaseOptions): void
|
|
23
|
+
readonly only: TestApi
|
|
24
|
+
readonly skip: TestApi
|
|
25
|
+
todo(name: string): void
|
|
26
|
+
readonly each: Each
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface DescribeApi {
|
|
30
|
+
(name: string, callback: () => void): void
|
|
31
|
+
readonly only: DescribeApi
|
|
32
|
+
readonly skip: DescribeApi
|
|
33
|
+
readonly each: Each
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AsymmetricMatcher {
|
|
37
|
+
asymmetricMatch(value: unknown): boolean
|
|
38
|
+
toString(): string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface MatcherResult {
|
|
42
|
+
pass: boolean
|
|
43
|
+
message(): string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type MatcherFunction = (
|
|
47
|
+
received: unknown,
|
|
48
|
+
...expected: unknown[]
|
|
49
|
+
) => Awaitable<MatcherResult>
|
|
50
|
+
|
|
51
|
+
/** Augment this interface to type matchers registered through `expect.extend()`. */
|
|
52
|
+
export interface CustomMatchers {}
|
|
53
|
+
|
|
54
|
+
export interface Matchers<R = void> extends CustomMatchers {
|
|
55
|
+
readonly not: Matchers<R>
|
|
56
|
+
readonly resolves: Matchers<Promise<void>>
|
|
57
|
+
readonly rejects: Matchers<Promise<void>>
|
|
58
|
+
toBe(expected: unknown): R
|
|
59
|
+
toEqual(expected: unknown): R
|
|
60
|
+
toStrictEqual(expected: unknown): R
|
|
61
|
+
toBeDefined(): R
|
|
62
|
+
toBeUndefined(): R
|
|
63
|
+
toBeNull(): R
|
|
64
|
+
toBeTruthy(): R
|
|
65
|
+
toBeFalsy(): R
|
|
66
|
+
toBeNaN(): R
|
|
67
|
+
toBeGreaterThan(expected: number | bigint): R
|
|
68
|
+
toBeGreaterThanOrEqual(expected: number | bigint): R
|
|
69
|
+
toBeLessThan(expected: number | bigint): R
|
|
70
|
+
toBeLessThanOrEqual(expected: number | bigint): R
|
|
71
|
+
toBeCloseTo(expected: number, digits?: number): R
|
|
72
|
+
toContain(expected: unknown): R
|
|
73
|
+
toContainEqual(expected: unknown): R
|
|
74
|
+
toHaveLength(expected: number): R
|
|
75
|
+
toMatch(expected: string | RegExp): R
|
|
76
|
+
toMatchObject(expected: object): R
|
|
77
|
+
toHaveProperty(path: string | readonly (string | number)[], expected?: unknown): R
|
|
78
|
+
toBeInstanceOf(expected: Function): R
|
|
79
|
+
toThrow(expected?: string | RegExp | Function | Error): R
|
|
80
|
+
toHaveBeenCalled(): R
|
|
81
|
+
toHaveBeenCalledTimes(count: number): R
|
|
82
|
+
toHaveBeenCalledWith(...expected: unknown[]): R
|
|
83
|
+
toHaveBeenLastCalledWith(...expected: unknown[]): R
|
|
84
|
+
toHaveBeenNthCalledWith(call: number, ...expected: unknown[]): R
|
|
85
|
+
toHaveReturned(): R
|
|
86
|
+
toHaveReturnedTimes(count: number): R
|
|
87
|
+
toHaveReturnedWith(expected: unknown): R
|
|
88
|
+
toHaveLastReturnedWith(expected: unknown): R
|
|
89
|
+
toHaveNthReturnedWith(call: number, expected: unknown): R
|
|
90
|
+
toMatchSnapshot(propertyMatchers?: object, hint?: string): R
|
|
91
|
+
/** Browser-only exact visual snapshot for the current viewport or received Element. */
|
|
92
|
+
toMatchScreenshot(hint?: string): Promise<void>
|
|
93
|
+
toBeInTheDocument(): R
|
|
94
|
+
toContainElement(element: Element | null): R
|
|
95
|
+
toContainHTML(html: string): R
|
|
96
|
+
toBeEmptyDOMElement(): R
|
|
97
|
+
toBeVisible(): R
|
|
98
|
+
toBeEnabled(): R
|
|
99
|
+
toBeDisabled(): R
|
|
100
|
+
toHaveAttribute(name: string, value?: string | RegExp): R
|
|
101
|
+
toHaveClass(...classNames: string[]): R
|
|
102
|
+
toHaveStyle(style: string | Record<string, string | number>): R
|
|
103
|
+
toHaveTextContent(text: string | RegExp, options?: { normalizeWhitespace?: boolean }): R
|
|
104
|
+
toHaveValue(value?: string | number | readonly string[]): R
|
|
105
|
+
toHaveDisplayValue(value: string | RegExp | readonly (string | RegExp)[]): R
|
|
106
|
+
toHaveFormValues(values: Record<string, unknown>): R
|
|
107
|
+
toHaveFocus(): R
|
|
108
|
+
toBeChecked(): R
|
|
109
|
+
toBePartiallyChecked(): R
|
|
110
|
+
toBeRequired(): R
|
|
111
|
+
toBeInvalid(): R
|
|
112
|
+
toBeValid(): R
|
|
113
|
+
toHaveAccessibleName(name?: string | RegExp): R
|
|
114
|
+
toHaveAccessibleDescription(description?: string | RegExp): R
|
|
115
|
+
toHaveAccessibleErrorMessage(message?: string | RegExp): R
|
|
116
|
+
toHaveRole(role: string): R
|
|
117
|
+
toHaveSelection(selection: string): R
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface Expect {
|
|
121
|
+
<T>(received: T): Matchers
|
|
122
|
+
extend(matchers: Readonly<Record<string, MatcherFunction>>): void
|
|
123
|
+
addEqualityTesters(testers: readonly ((left: unknown, right: unknown) => boolean | undefined)[]): void
|
|
124
|
+
addSnapshotSerializer(serializer: {
|
|
125
|
+
test(value: unknown): boolean
|
|
126
|
+
print(value: unknown, serialize: (value: unknown) => string): string
|
|
127
|
+
}): void
|
|
128
|
+
assertions(count: number): void
|
|
129
|
+
hasAssertions(): void
|
|
130
|
+
getState(): Readonly<Record<string, unknown>>
|
|
131
|
+
setState(state: Readonly<Record<string, unknown>>): void
|
|
132
|
+
anything(): AsymmetricMatcher
|
|
133
|
+
any(constructor: Function): AsymmetricMatcher
|
|
134
|
+
arrayContaining(sample: readonly unknown[]): AsymmetricMatcher
|
|
135
|
+
objectContaining(sample: object): AsymmetricMatcher
|
|
136
|
+
stringContaining(sample: string): AsymmetricMatcher
|
|
137
|
+
stringMatching(sample: string | RegExp): AsymmetricMatcher
|
|
138
|
+
closeTo(sample: number, digits?: number): AsymmetricMatcher
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type AnyFunction = (...args: any[]) => any
|
|
142
|
+
|
|
143
|
+
export interface MockResult {
|
|
144
|
+
type: 'return' | 'throw' | 'incomplete'
|
|
145
|
+
value: unknown
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface MockState<T extends AnyFunction> {
|
|
149
|
+
calls: Parameters<T>[]
|
|
150
|
+
contexts: unknown[]
|
|
151
|
+
instances: unknown[]
|
|
152
|
+
invocationCallOrder: number[]
|
|
153
|
+
results: MockResult[]
|
|
154
|
+
lastCall?: Parameters<T>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface MockFunction<T extends AnyFunction = AnyFunction> {
|
|
158
|
+
(...args: Parameters<T>): ReturnType<T>
|
|
159
|
+
readonly isMockFunction: true
|
|
160
|
+
readonly calls: Readonly<MockState<T>>
|
|
161
|
+
clear(): this
|
|
162
|
+
reset(): this
|
|
163
|
+
restore(): void
|
|
164
|
+
implement(implementation: T): this
|
|
165
|
+
implementOnce(implementation: T): this
|
|
166
|
+
return(value: ReturnType<T>): this
|
|
167
|
+
returnOnce(value: ReturnType<T>): this
|
|
168
|
+
resolve(value: Awaited<ReturnType<T>>): this
|
|
169
|
+
resolveOnce(value: Awaited<ReturnType<T>>): this
|
|
170
|
+
reject(reason: unknown): this
|
|
171
|
+
rejectOnce(reason: unknown): this
|
|
172
|
+
named(name: string): this
|
|
173
|
+
readonly name: string
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface ReplacedProperty<T> {
|
|
177
|
+
replace(value: T): void
|
|
178
|
+
restore(): void
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface MockApi {
|
|
182
|
+
fn<T extends AnyFunction = AnyFunction>(implementation?: T): MockFunction<T>
|
|
183
|
+
spyOn<T extends object, K extends keyof T>(
|
|
184
|
+
object: T,
|
|
185
|
+
key: K,
|
|
186
|
+
accessType?: 'get' | 'set',
|
|
187
|
+
): T[K] extends AnyFunction ? MockFunction<T[K]> : MockFunction
|
|
188
|
+
replaceProperty<T extends object, K extends keyof T>(object: T, key: K, value: T[K]): ReplacedProperty<T[K]>
|
|
189
|
+
module<T = unknown>(specifier: string, factory: () => Awaitable<T>): void
|
|
190
|
+
import<T = unknown>(specifier: string): Promise<T>
|
|
191
|
+
actual<T = unknown>(specifier: string): Promise<T>
|
|
192
|
+
isolate<T>(callback: () => Awaitable<T>): Promise<T>
|
|
193
|
+
clearAll(): void
|
|
194
|
+
resetAll(): void
|
|
195
|
+
restoreAll(): void
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface FakeClockOptions {
|
|
199
|
+
now?: number | Date
|
|
200
|
+
timerLimit?: number
|
|
201
|
+
exclude?: readonly ('date' | 'performance' | 'timeout' | 'interval' | 'immediate' | 'microtask' | 'animationFrame' | 'idleCallback')[]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ClockApi {
|
|
205
|
+
fake(options?: FakeClockOptions): Promise<ClockApi>
|
|
206
|
+
restore(): Promise<ClockApi>
|
|
207
|
+
advanceBy(milliseconds: number): Promise<void>
|
|
208
|
+
advanceTo(timestamp: number | Date): Promise<void>
|
|
209
|
+
runNext(): Promise<boolean>
|
|
210
|
+
runAll(): Promise<void>
|
|
211
|
+
flushMicrotasks(): Promise<void>
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface NetworkRequest {
|
|
215
|
+
readonly id: string
|
|
216
|
+
readonly url: URL
|
|
217
|
+
readonly method: string
|
|
218
|
+
readonly headers: Headers
|
|
219
|
+
readonly body: Uint8Array | null
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface NetworkResponse {
|
|
223
|
+
status?: number
|
|
224
|
+
statusText?: string
|
|
225
|
+
headers?: HeadersInit
|
|
226
|
+
body?: BodyInit | object | null
|
|
227
|
+
delayMs?: number
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export type NetworkMatcher =
|
|
231
|
+
| string
|
|
232
|
+
| URL
|
|
233
|
+
| RegExp
|
|
234
|
+
| {
|
|
235
|
+
method?: string
|
|
236
|
+
url?: string | URL | RegExp
|
|
237
|
+
}
|
|
238
|
+
| ((request: NetworkRequest) => boolean)
|
|
239
|
+
|
|
240
|
+
export type NetworkHandler = (
|
|
241
|
+
request: NetworkRequest,
|
|
242
|
+
) => Awaitable<NetworkResponse | Response>
|
|
243
|
+
|
|
244
|
+
export interface NetworkDisposer {
|
|
245
|
+
(): void
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface NetworkApi {
|
|
249
|
+
route(matcher: NetworkMatcher, handler: NetworkHandler): NetworkDisposer
|
|
250
|
+
allow(matcher: NetworkMatcher): NetworkDisposer
|
|
251
|
+
requests(): readonly NetworkRequest[]
|
|
252
|
+
reset(): void
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const test: TestApi
|
|
256
|
+
export const it: TestApi
|
|
257
|
+
export const describe: DescribeApi
|
|
258
|
+
export const beforeAll: (callback: TestCallback, options?: TestCaseOptions) => void
|
|
259
|
+
export const beforeEach: (callback: TestCallback, options?: TestCaseOptions) => void
|
|
260
|
+
export const afterAll: (callback: TestCallback, options?: TestCaseOptions) => void
|
|
261
|
+
export const afterEach: (callback: TestCallback, options?: TestCaseOptions) => void
|
|
262
|
+
export const expect: Expect
|
|
263
|
+
export const mock: MockApi
|
|
264
|
+
export const clock: ClockApi
|
|
265
|
+
export const network: NetworkApi
|