Skip to content

Commit

Permalink
change to use react act
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed May 13, 2024
1 parent 6374073 commit 50cd557
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 203 deletions.
2 changes: 1 addition & 1 deletion packages/reshow-unit/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.17.35",
"version": "0.18.0",
"name": "reshow-unit",
"repository": {
"type": "git",
Expand Down
9 changes: 4 additions & 5 deletions packages/reshow-unit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getDefault } from "get-object-value";

import { waitFor, waitForElementToBeRemoved } from "@testing-library/dom";
import {
act as rtlAct,
render as rtlRender,
cleanup,
getQueriesForElement,
Expand All @@ -23,7 +22,7 @@ import {
import userEvent from "@testing-library/user-event";
import { env } from "process";
import build from "reshow-build";
import { StrictMode } from "react";
import { StrictMode, act as rtlAct } from "react";

const envStrictMode = /** @type string*/ (env.STRICT_MODE);
const STRICT_MODE =
Expand Down Expand Up @@ -101,7 +100,7 @@ const act = async (cb = () => {}, milliseconds = 1, debug = false) => {
/**
* rtl-render: https://github.com/testing-library/react-testing-library/blob/main/src/pure.js
*
* @param {import("react").ReactElement} OrigDom
* @param {React.ReactElement} OrigDom
* @param {object} options
* @returns {import("@testing-library/react").RenderResult & RenderResult}
*/
Expand All @@ -116,10 +115,10 @@ const render = (OrigDom, options = {}) => {
*/
instance = (el) => (uInstance = el);
}
Dom = build(OrigDom)({ ref: instance });
Dom = /** @type React.ReactElement*/ (build(OrigDom)({ ref: instance }));
}
if (STRICT_MODE) {
Dom = build(StrictMode)(undefined, Dom);
Dom = /** @type React.ReactElement*/ (build(StrictMode)(undefined, Dom));
}
const result = {
...rtlRender(Dom, options),
Expand Down
8 changes: 6 additions & 2 deletions packages/reshow-unit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ export function act(cb?: Function, milliseconds?: number, debug?: boolean): Prom
/**
* rtl-render: https://github.com/testing-library/react-testing-library/blob/main/src/pure.js
*
* @param {import("react").ReactElement} OrigDom
* @param {React.ReactElement} OrigDom
* @param {object} options
* @returns {import("@testing-library/react").RenderResult & RenderResult}
*/
export function render(OrigDom: import("react").ReactElement, options?: object): import("@testing-library/react").RenderResult & RenderResult;
export function render(OrigDom: React.ReactElement, options?: object): import("@testing-library/react").RenderResult & RenderResult;
export function screen(): {
getByLabelText<T extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions): T;
getAllByLabelText<T_1 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions): T_1[];
queryByLabelText<T_2 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions): T_2;
queryAllByLabelText<T_3 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions): T_3[];
findByLabelText<T_4 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions, waitForElementOptions?: import("@testing-library/dom").waitForOptions): Promise<T_4>;
findAllByLabelText<T_5 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").SelectorMatcherOptions, waitForElementOptions?: import("@testing-library/dom").waitForOptions): Promise<T_5[]>;
/**
* @param {string} role
* @returns {string}
*/
getByPlaceholderText<T_6 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions): T_6;
getAllByPlaceholderText<T_7 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions): T_7[];
queryByPlaceholderText<T_8 extends HTMLElement = HTMLElement>(id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions): T_8;
Expand Down
Loading

0 comments on commit 50cd557

Please sign in to comment.