@rstest/browser-react 0.7.9
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 +269 -0
- package/dist/879.js +111 -0
- package/dist/act.d.ts +8 -0
- package/dist/act.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/pure.d.ts +63 -0
- package/dist/pure.d.ts.map +1 -0
- package/dist/pure.js +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# @rstest/browser-react
|
|
2
|
+
|
|
3
|
+
React component testing utilities for [Rstest](https://rstest.dev) browser mode.
|
|
4
|
+
|
|
5
|
+
This package provides `render` and `renderHook` functions for testing React components in a real browser environment. Tests run in an actual browser rather than a simulated DOM like jsdom.
|
|
6
|
+
|
|
7
|
+
For a complete working example, see the [browser example](../../examples/browser-react) in the Rstest repository.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @rstest/browser-react
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @rstest/browser-react
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For DOM queries and user interactions, also install:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @testing-library/dom @testing-library/user-event
|
|
21
|
+
# or
|
|
22
|
+
pnpm install @testing-library/dom @testing-library/user-event
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic component testing
|
|
28
|
+
|
|
29
|
+
Use the `render` function to mount a React component into the DOM. This is the foundation for all component tests:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { render } from '@rstest/browser-react';
|
|
33
|
+
import { getByRole, getByText } from '@testing-library/dom';
|
|
34
|
+
import { expect, test } from '@rstest/core';
|
|
35
|
+
|
|
36
|
+
test('renders button with text', async () => {
|
|
37
|
+
const { container } = await render(<button>Click me</button>);
|
|
38
|
+
|
|
39
|
+
expect(getByRole(container, 'button')).toBeTruthy();
|
|
40
|
+
expect(getByText(container, 'Click me')).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Testing with providers
|
|
45
|
+
|
|
46
|
+
When your component depends on React Context (e.g., theme, auth, store), use the `wrapper` option to wrap it with the necessary providers:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { render } from '@rstest/browser-react';
|
|
50
|
+
|
|
51
|
+
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
52
|
+
<ThemeProvider theme="dark">{children}</ThemeProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
test('renders with theme context', async () => {
|
|
56
|
+
const { container } = await render(<MyComponent />, { wrapper: Wrapper });
|
|
57
|
+
// ...assertions
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### User interactions
|
|
62
|
+
|
|
63
|
+
Simulate realistic user interactions (clicks, typing, etc.) using `@testing-library/user-event`:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { render } from '@rstest/browser-react';
|
|
67
|
+
import { getByRole, getByText } from '@testing-library/dom';
|
|
68
|
+
import userEvent from '@testing-library/user-event';
|
|
69
|
+
import { expect, test } from '@rstest/core';
|
|
70
|
+
|
|
71
|
+
test('increments counter on click', async () => {
|
|
72
|
+
const { container } = await render(<Counter />);
|
|
73
|
+
const button = getByRole(container, 'button');
|
|
74
|
+
|
|
75
|
+
await userEvent.click(button);
|
|
76
|
+
|
|
77
|
+
expect(getByText(container, 'Count: 1')).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Testing hooks
|
|
82
|
+
|
|
83
|
+
Use `renderHook` to test custom hooks in isolation, without needing to create a wrapper component. The returned `act` function ensures state updates are properly flushed:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { renderHook } from '@rstest/browser-react';
|
|
87
|
+
import { useState } from 'react';
|
|
88
|
+
import { expect, test } from '@rstest/core';
|
|
89
|
+
|
|
90
|
+
test('useState updates value', async () => {
|
|
91
|
+
const { result, act } = await renderHook(() => useState(0));
|
|
92
|
+
|
|
93
|
+
expect(result.current[0]).toBe(0);
|
|
94
|
+
|
|
95
|
+
await act(() => {
|
|
96
|
+
result.current[1](1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(result.current[0]).toBe(1);
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Testing hooks with props
|
|
104
|
+
|
|
105
|
+
When your hook depends on props, use `initialProps` and `rerender` to test how the hook responds to prop changes:
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { renderHook } from '@rstest/browser-react';
|
|
109
|
+
import { useMemo } from 'react';
|
|
110
|
+
import { expect, test } from '@rstest/core';
|
|
111
|
+
|
|
112
|
+
test('hook reacts to prop changes', async () => {
|
|
113
|
+
const { result, rerender } = await renderHook(
|
|
114
|
+
(props) => useMemo(() => (props?.value ?? 0) * 2, [props?.value]),
|
|
115
|
+
{ initialProps: { value: 5 } },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(result.current).toBe(10);
|
|
119
|
+
|
|
120
|
+
await rerender({ value: 10 });
|
|
121
|
+
|
|
122
|
+
expect(result.current).toBe(20);
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### React strict mode
|
|
127
|
+
|
|
128
|
+
To enable React Strict Mode for catching potential issues, use the `configure` function:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { configure } from '@rstest/browser-react';
|
|
132
|
+
|
|
133
|
+
configure({ reactStrictMode: true });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Pure entry
|
|
137
|
+
|
|
138
|
+
The `/pure` entry (`@rstest/browser-react/pure`) exports the same API but without automatic cleanup registration. Use it when you need manual control over cleanup timing:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { cleanup, render } from '@rstest/browser-react/pure';
|
|
142
|
+
import { afterEach } from '@rstest/core';
|
|
143
|
+
|
|
144
|
+
afterEach(async () => {
|
|
145
|
+
await cleanup();
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## API reference
|
|
150
|
+
|
|
151
|
+
### Exports
|
|
152
|
+
|
|
153
|
+
The default entry (`@rstest/browser-react`) exports:
|
|
154
|
+
|
|
155
|
+
- `render` - Render a React element into the DOM
|
|
156
|
+
- `renderHook` - Render a custom hook for testing
|
|
157
|
+
- `cleanup` - Unmount all rendered components
|
|
158
|
+
- `act` - Wrap state updates for proper batching
|
|
159
|
+
- `configure` - Configure render behavior (e.g., React Strict Mode)
|
|
160
|
+
|
|
161
|
+
Type exports:
|
|
162
|
+
|
|
163
|
+
- `RenderOptions` - Options for `render()`
|
|
164
|
+
- `RenderResult` - Return type of `render()`
|
|
165
|
+
- `RenderHookOptions` - Options for `renderHook()`
|
|
166
|
+
- `RenderHookResult` - Return type of `renderHook()`
|
|
167
|
+
- `RenderConfiguration` - Options for `configure()`
|
|
168
|
+
|
|
169
|
+
The `/pure` entry exports the same API but does not register automatic cleanup hooks.
|
|
170
|
+
|
|
171
|
+
### `render(ui, options?)`
|
|
172
|
+
|
|
173
|
+
Renders a React element into the DOM.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
function render(ui: ReactNode, options?: RenderOptions): Promise<RenderResult>;
|
|
177
|
+
|
|
178
|
+
interface RenderOptions {
|
|
179
|
+
/** Custom container element to render into */
|
|
180
|
+
container?: HTMLElement;
|
|
181
|
+
/** Base element for queries, defaults to document.body */
|
|
182
|
+
baseElement?: HTMLElement;
|
|
183
|
+
/** Wrapper component (e.g., for providers/context) */
|
|
184
|
+
wrapper?: JSXElementConstructor<{ children: ReactNode }>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface RenderResult {
|
|
188
|
+
/** The container element the component is rendered into */
|
|
189
|
+
container: HTMLElement;
|
|
190
|
+
/** The base element for queries, defaults to document.body */
|
|
191
|
+
baseElement: HTMLElement;
|
|
192
|
+
/** Unmount the rendered component */
|
|
193
|
+
unmount: () => Promise<void>;
|
|
194
|
+
/** Re-render the component with new props/element */
|
|
195
|
+
rerender: (ui: ReactNode) => Promise<void>;
|
|
196
|
+
/** Returns the rendered UI as a DocumentFragment (useful for snapshots) */
|
|
197
|
+
asFragment: () => DocumentFragment;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `renderHook(callback, options?)`
|
|
202
|
+
|
|
203
|
+
Renders a custom React hook for testing.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
function renderHook<Props, Result>(
|
|
207
|
+
callback: (props?: Props) => Result,
|
|
208
|
+
options?: RenderHookOptions<Props>,
|
|
209
|
+
): Promise<RenderHookResult<Result, Props>>;
|
|
210
|
+
|
|
211
|
+
interface RenderHookOptions<Props> extends RenderOptions {
|
|
212
|
+
/** Initial props passed to the hook */
|
|
213
|
+
initialProps?: Props;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface RenderHookResult<Result, Props> {
|
|
217
|
+
/** Reference to the latest hook return value */
|
|
218
|
+
result: { current: Result };
|
|
219
|
+
/** Re-render the hook with new props */
|
|
220
|
+
rerender: (props?: Props) => Promise<void>;
|
|
221
|
+
/** Unmount the hook */
|
|
222
|
+
unmount: () => Promise<void>;
|
|
223
|
+
/** Access to act for manual state updates */
|
|
224
|
+
act: (callback: () => unknown) => Promise<void>;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### `act(callback)`
|
|
229
|
+
|
|
230
|
+
Wraps state updates in React's `act()` for proper batching. Automatically manages the `IS_REACT_ACT_ENVIRONMENT` global.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
function act(callback: () => unknown): Promise<void>;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
> **Note:** For React 17 (which doesn't export `act`), this function falls back to simple async execution.
|
|
237
|
+
|
|
238
|
+
### `cleanup()`
|
|
239
|
+
|
|
240
|
+
Unmounts all rendered components and removes their containers from the DOM.
|
|
241
|
+
|
|
242
|
+
Called automatically **before** each test when using the default entry. This timing allows you to inspect the DOM after a test failure.
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
function cleanup(): Promise<void>;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### `configure(options)`
|
|
249
|
+
|
|
250
|
+
Configure render behavior.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
function configure(options: Partial<RenderConfiguration>): void;
|
|
254
|
+
|
|
255
|
+
interface RenderConfiguration {
|
|
256
|
+
/** Enable React StrictMode wrapper (default: false) */
|
|
257
|
+
reactStrictMode: boolean;
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Compatibility
|
|
262
|
+
|
|
263
|
+
- React 17, 18, and 19
|
|
264
|
+
- Rstest browser mode
|
|
265
|
+
- Node.js >= 18.12.0
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT
|
package/dist/879.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { StrictMode, act, createElement, useEffect } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
let activeActs = 0;
|
|
4
|
+
function setActEnvironment(value) {
|
|
5
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = value;
|
|
6
|
+
}
|
|
7
|
+
function updateActEnvironment() {
|
|
8
|
+
setActEnvironment(activeActs > 0);
|
|
9
|
+
}
|
|
10
|
+
const _act = act;
|
|
11
|
+
const act_act = 'function' != typeof _act ? async (callback)=>{
|
|
12
|
+
await callback();
|
|
13
|
+
} : async (callback)=>{
|
|
14
|
+
activeActs++;
|
|
15
|
+
updateActEnvironment();
|
|
16
|
+
try {
|
|
17
|
+
await _act(callback);
|
|
18
|
+
} finally{
|
|
19
|
+
activeActs--;
|
|
20
|
+
updateActEnvironment();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const mountedContainers = new Set();
|
|
24
|
+
const mountedRootEntries = [];
|
|
25
|
+
const config = {
|
|
26
|
+
reactStrictMode: false
|
|
27
|
+
};
|
|
28
|
+
function pure_createRoot(container) {
|
|
29
|
+
const root = createRoot(container);
|
|
30
|
+
return {
|
|
31
|
+
render: (element)=>root.render(element),
|
|
32
|
+
unmount: ()=>root.unmount()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function strictModeIfNeeded(ui) {
|
|
36
|
+
return config.reactStrictMode ? /*#__PURE__*/ createElement(StrictMode, null, ui) : ui;
|
|
37
|
+
}
|
|
38
|
+
function wrapUiIfNeeded(ui, wrapper) {
|
|
39
|
+
return wrapper ? /*#__PURE__*/ createElement(wrapper, null, ui) : ui;
|
|
40
|
+
}
|
|
41
|
+
async function render(ui, options = {}) {
|
|
42
|
+
const { wrapper } = options;
|
|
43
|
+
let { container, baseElement } = options;
|
|
44
|
+
if (!baseElement) baseElement = document.body;
|
|
45
|
+
if (!container) container = baseElement.appendChild(document.createElement('div'));
|
|
46
|
+
let root;
|
|
47
|
+
if (mountedContainers.has(container)) {
|
|
48
|
+
const entry = mountedRootEntries.find((e)=>e.container === container);
|
|
49
|
+
if (!entry) throw new Error('Container is tracked but root entry not found');
|
|
50
|
+
root = entry.root;
|
|
51
|
+
} else {
|
|
52
|
+
root = pure_createRoot(container);
|
|
53
|
+
mountedRootEntries.push({
|
|
54
|
+
container,
|
|
55
|
+
root
|
|
56
|
+
});
|
|
57
|
+
mountedContainers.add(container);
|
|
58
|
+
}
|
|
59
|
+
const wrappedUi = wrapUiIfNeeded(strictModeIfNeeded(ui), wrapper);
|
|
60
|
+
await act_act(()=>root.render(wrappedUi));
|
|
61
|
+
return {
|
|
62
|
+
container,
|
|
63
|
+
baseElement,
|
|
64
|
+
unmount: async ()=>{
|
|
65
|
+
await act_act(()=>root.unmount());
|
|
66
|
+
},
|
|
67
|
+
rerender: async (newUi)=>{
|
|
68
|
+
const wrapped = wrapUiIfNeeded(strictModeIfNeeded(newUi), wrapper);
|
|
69
|
+
await act_act(()=>root.render(wrapped));
|
|
70
|
+
},
|
|
71
|
+
asFragment: ()=>document.createRange().createContextualFragment(container.innerHTML)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function renderHook(renderCallback, options = {}) {
|
|
75
|
+
const { initialProps, ...renderOptions } = options;
|
|
76
|
+
const result = {
|
|
77
|
+
current: void 0
|
|
78
|
+
};
|
|
79
|
+
function TestComponent({ hookProps }) {
|
|
80
|
+
const value = renderCallback(hookProps);
|
|
81
|
+
useEffect(()=>{
|
|
82
|
+
result.current = value;
|
|
83
|
+
});
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const { rerender: baseRerender, unmount } = await render(/*#__PURE__*/ createElement(TestComponent, {
|
|
87
|
+
hookProps: initialProps
|
|
88
|
+
}), renderOptions);
|
|
89
|
+
return {
|
|
90
|
+
result,
|
|
91
|
+
rerender: async (props)=>{
|
|
92
|
+
await baseRerender(/*#__PURE__*/ createElement(TestComponent, {
|
|
93
|
+
hookProps: props
|
|
94
|
+
}));
|
|
95
|
+
},
|
|
96
|
+
unmount,
|
|
97
|
+
act: act_act
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function cleanup() {
|
|
101
|
+
for (const { root, container } of mountedRootEntries){
|
|
102
|
+
await act_act(()=>root.unmount());
|
|
103
|
+
if (container.parentNode === document.body) document.body.removeChild(container);
|
|
104
|
+
}
|
|
105
|
+
mountedRootEntries.length = 0;
|
|
106
|
+
mountedContainers.clear();
|
|
107
|
+
}
|
|
108
|
+
function configure(customConfig) {
|
|
109
|
+
Object.assign(config, customConfig);
|
|
110
|
+
}
|
|
111
|
+
export { act_act as act, cleanup, configure, render, renderHook };
|
package/dist/act.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ActFunction = (callback: () => unknown) => Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a callback in React's act() for proper state updates.
|
|
4
|
+
* Automatically manages IS_REACT_ACT_ENVIRONMENT.
|
|
5
|
+
*/
|
|
6
|
+
export declare const act: ActFunction;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=act.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../src/act.ts"],"names":[],"mappings":"AAiBA,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,WAcX,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { act, cleanup, configure, render, renderHook } from './pure';
|
|
2
|
+
export { render, renderHook, cleanup, act, configure };
|
|
3
|
+
export type { RenderConfiguration, RenderHookOptions, RenderHookResult, RenderOptions, RenderResult, } from './pure';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAQrE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;AACvD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,GACb,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
package/dist/pure.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { JSXElementConstructor, ReactNode } from 'react';
|
|
2
|
+
import { act } from './act';
|
|
3
|
+
export interface RenderResult {
|
|
4
|
+
/** The container element the component is rendered into */
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
/** The base element for queries, defaults to document.body */
|
|
7
|
+
baseElement: HTMLElement;
|
|
8
|
+
/** Unmount the rendered component */
|
|
9
|
+
unmount: () => Promise<void>;
|
|
10
|
+
/** Re-render the component with new props/element */
|
|
11
|
+
rerender: (ui: ReactNode) => Promise<void>;
|
|
12
|
+
/** Returns the rendered UI as a DocumentFragment (useful for snapshots) */
|
|
13
|
+
asFragment: () => DocumentFragment;
|
|
14
|
+
}
|
|
15
|
+
export interface RenderOptions {
|
|
16
|
+
/** Custom container element to render into */
|
|
17
|
+
container?: HTMLElement;
|
|
18
|
+
/** Base element for queries, defaults to document.body */
|
|
19
|
+
baseElement?: HTMLElement;
|
|
20
|
+
/** Wrapper component (e.g., for providers/context) */
|
|
21
|
+
wrapper?: JSXElementConstructor<{
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface RenderHookOptions<Props> extends RenderOptions {
|
|
26
|
+
/** Initial props passed to the hook */
|
|
27
|
+
initialProps?: Props;
|
|
28
|
+
}
|
|
29
|
+
export interface RenderHookResult<Result, Props> {
|
|
30
|
+
/** Reference to the latest hook return value */
|
|
31
|
+
result: {
|
|
32
|
+
current: Result;
|
|
33
|
+
};
|
|
34
|
+
/** Re-render the hook with new props */
|
|
35
|
+
rerender: (props?: Props) => Promise<void>;
|
|
36
|
+
/** Unmount the hook */
|
|
37
|
+
unmount: () => Promise<void>;
|
|
38
|
+
/** Access to act for manual state updates */
|
|
39
|
+
act: (callback: () => unknown) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface RenderConfiguration {
|
|
42
|
+
/** Enable React StrictMode wrapper */
|
|
43
|
+
reactStrictMode: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Render a React element into the DOM.
|
|
47
|
+
*/
|
|
48
|
+
export declare function render(ui: ReactNode, options?: RenderOptions): Promise<RenderResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Render a custom React hook for testing.
|
|
51
|
+
*/
|
|
52
|
+
export declare function renderHook<Props, Result>(renderCallback: (props?: Props) => Result, options?: RenderHookOptions<Props>): Promise<RenderHookResult<Result, Props>>;
|
|
53
|
+
/**
|
|
54
|
+
* Cleanup all mounted components.
|
|
55
|
+
* Call this in beforeEach or afterEach to prevent test pollution.
|
|
56
|
+
*/
|
|
57
|
+
export declare function cleanup(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Configure render behavior.
|
|
60
|
+
*/
|
|
61
|
+
export declare function configure(customConfig: Partial<RenderConfiguration>): void;
|
|
62
|
+
export { act };
|
|
63
|
+
//# sourceMappingURL=pure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG9D,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAI5B,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,SAAS,EAAE,WAAW,CAAC;IACvB,8DAA8D;IAC9D,WAAW,EAAE,WAAW,CAAC;IACzB,qCAAqC;IACrC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,2EAA2E;IAC3E,UAAU,EAAE,MAAM,gBAAgB,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,sDAAsD;IACtD,OAAO,CAAC,EAAE,qBAAqB,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,iBAAiB,CAAC,KAAK,CAAE,SAAQ,aAAa;IAC7D,uCAAuC;IACvC,YAAY,CAAC,EAAE,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,MAAM,EAAE,KAAK;IAC7C,gDAAgD;IAChD,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5B,wCAAwC;IACxC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,uBAAuB;IACvB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,6CAA6C;IAC7C,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,eAAe,EAAE,OAAO,CAAC;CAC1B;AA8CD;;GAEG;AACH,wBAAsB,MAAM,CAC1B,EAAE,EAAE,SAAS,EACb,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA8CvB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAC5C,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,MAAM,EACzC,OAAO,GAAE,iBAAiB,CAAC,KAAK,CAAM,GACrC,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CA2B1C;AAED;;;GAGG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAS7C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAE1E;AAED,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/pure.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { act, cleanup, configure, render, renderHook } from "./879.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rstest/browser-react",
|
|
3
|
+
"version": "0.7.9",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "React component testing support for Rstest browser mode",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./pure": {
|
|
13
|
+
"types": "./dist/pure.d.ts",
|
|
14
|
+
"default": "./dist/pure.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": {
|
|
17
|
+
"default": "./package.json"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rslib build",
|
|
27
|
+
"dev": "cross-env SOURCEMAP=true rslib build --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "rstest"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@rstest/core": "workspace:^",
|
|
33
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
34
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@rslib/core": "^0.19.0",
|
|
38
|
+
"@rstest/core": "workspace:*",
|
|
39
|
+
"@rstest/tsconfig": "workspace:*",
|
|
40
|
+
"@types/react": "^19.2.7",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
42
|
+
"react": "^19.2.3",
|
|
43
|
+
"react-dom": "^19.2.3",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"rstest",
|
|
48
|
+
"react",
|
|
49
|
+
"testing",
|
|
50
|
+
"browser",
|
|
51
|
+
"component"
|
|
52
|
+
],
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/web-infra-dev/rstest/issues"
|
|
55
|
+
},
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/web-infra-dev/rstest",
|
|
59
|
+
"directory": "packages/browser-react"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.12.0"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public",
|
|
66
|
+
"registry": "https://registry.npmjs.org/"
|
|
67
|
+
}
|
|
68
|
+
}
|