@rstest/browser-react 0.9.2 → 0.9.4
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/pure.js +14 -14
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { act, cleanup, configure, render, renderHook } from './pure';
|
|
2
|
-
export { render, renderHook, cleanup, act, configure };
|
|
3
2
|
export type { RenderConfiguration, RenderHookOptions, RenderHookResult, RenderOptions, RenderResult, } from './pure';
|
|
3
|
+
export { act, cleanup, configure, render, renderHook };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,GACb,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/pure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
3
|
let activeActs = 0;
|
|
4
4
|
function setActEnvironment(value) {
|
|
@@ -7,8 +7,8 @@ function setActEnvironment(value) {
|
|
|
7
7
|
function updateActEnvironment() {
|
|
8
8
|
setActEnvironment(activeActs > 0);
|
|
9
9
|
}
|
|
10
|
-
const _act = act;
|
|
11
|
-
const
|
|
10
|
+
const _act = react.act;
|
|
11
|
+
const act = 'function' != typeof _act ? async (callback)=>{
|
|
12
12
|
await callback();
|
|
13
13
|
} : async (callback)=>{
|
|
14
14
|
activeActs++;
|
|
@@ -33,10 +33,10 @@ function pure_createRoot(container) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function strictModeIfNeeded(ui) {
|
|
36
|
-
return config.reactStrictMode ? /*#__PURE__*/ createElement(StrictMode, null, ui) : ui;
|
|
36
|
+
return config.reactStrictMode ? /*#__PURE__*/ react.createElement(react.StrictMode, null, ui) : ui;
|
|
37
37
|
}
|
|
38
38
|
function wrapUiIfNeeded(ui, wrapper) {
|
|
39
|
-
return wrapper ? /*#__PURE__*/ createElement(wrapper, null, ui) : ui;
|
|
39
|
+
return wrapper ? /*#__PURE__*/ react.createElement(wrapper, null, ui) : ui;
|
|
40
40
|
}
|
|
41
41
|
async function render(ui, options = {}) {
|
|
42
42
|
const { wrapper } = options;
|
|
@@ -57,16 +57,16 @@ async function render(ui, options = {}) {
|
|
|
57
57
|
mountedContainers.add(container);
|
|
58
58
|
}
|
|
59
59
|
const wrappedUi = wrapUiIfNeeded(strictModeIfNeeded(ui), wrapper);
|
|
60
|
-
await
|
|
60
|
+
await act(()=>root.render(wrappedUi));
|
|
61
61
|
return {
|
|
62
62
|
container,
|
|
63
63
|
baseElement,
|
|
64
64
|
unmount: async ()=>{
|
|
65
|
-
await
|
|
65
|
+
await act(()=>root.unmount());
|
|
66
66
|
},
|
|
67
67
|
rerender: async (newUi)=>{
|
|
68
68
|
const wrapped = wrapUiIfNeeded(strictModeIfNeeded(newUi), wrapper);
|
|
69
|
-
await
|
|
69
|
+
await act(()=>root.render(wrapped));
|
|
70
70
|
},
|
|
71
71
|
asFragment: ()=>document.createRange().createContextualFragment(container.innerHTML)
|
|
72
72
|
};
|
|
@@ -78,28 +78,28 @@ async function renderHook(renderCallback, options = {}) {
|
|
|
78
78
|
};
|
|
79
79
|
function TestComponent({ hookProps }) {
|
|
80
80
|
const value = renderCallback(hookProps);
|
|
81
|
-
useEffect(()=>{
|
|
81
|
+
react.useEffect(()=>{
|
|
82
82
|
result.current = value;
|
|
83
83
|
});
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
|
-
const { rerender: baseRerender, unmount } = await render(/*#__PURE__*/ createElement(TestComponent, {
|
|
86
|
+
const { rerender: baseRerender, unmount } = await render(/*#__PURE__*/ react.createElement(TestComponent, {
|
|
87
87
|
hookProps: initialProps
|
|
88
88
|
}), renderOptions);
|
|
89
89
|
return {
|
|
90
90
|
result,
|
|
91
91
|
rerender: async (props)=>{
|
|
92
|
-
await baseRerender(/*#__PURE__*/ createElement(TestComponent, {
|
|
92
|
+
await baseRerender(/*#__PURE__*/ react.createElement(TestComponent, {
|
|
93
93
|
hookProps: props
|
|
94
94
|
}));
|
|
95
95
|
},
|
|
96
96
|
unmount,
|
|
97
|
-
act:
|
|
97
|
+
act: act
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
async function cleanup() {
|
|
101
101
|
for (const { root, container } of mountedRootEntries){
|
|
102
|
-
await
|
|
102
|
+
await act(()=>root.unmount());
|
|
103
103
|
if (container.parentNode === document.body) document.body.removeChild(container);
|
|
104
104
|
}
|
|
105
105
|
mountedRootEntries.length = 0;
|
|
@@ -108,4 +108,4 @@ async function cleanup() {
|
|
|
108
108
|
function configure(customConfig) {
|
|
109
109
|
Object.assign(config, customConfig);
|
|
110
110
|
}
|
|
111
|
-
export {
|
|
111
|
+
export { act, cleanup, configure, render, renderHook };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstest/browser-react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React component testing support for Rstest browser mode",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
27
27
|
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
28
|
-
"@rstest/core": "^0.9.
|
|
28
|
+
"@rstest/core": "^0.9.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rslib/core": "0.20.0",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"react": "^19.2.4",
|
|
35
35
|
"react-dom": "^19.2.4",
|
|
36
36
|
"typescript": "^5.9.3",
|
|
37
|
-
"@rstest/
|
|
38
|
-
"@rstest/
|
|
37
|
+
"@rstest/tsconfig": "0.0.1",
|
|
38
|
+
"@rstest/core": "0.9.4"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"rstest",
|