Skip to content

Commit

Permalink
Merge branch '19' of github.com:/reasonml/reason-react into replace-t…
Browse files Browse the repository at this point in the history
…esting-libraries

* '19' of github.com:/reasonml/reason-react:
  Add deprecations on ReactDOMTestUtils
  Add uri comment back on action
  Update src/React.re
  Update src/React.re
  Update src/React.re
  Snapshot with lower {}
  • Loading branch information
davesnx committed Nov 25, 2024
2 parents b39168f + f5f5579 commit f7d55fe
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/React.re
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,16 @@ external useDebugValue: ('value, ~format: 'value => string=?, unit) => unit =

module Experimental = {
/* This module is used to bind to APIs for future versions of React. There is no guarantee of backwards compatibility or stability. */
/* https://react.dev/reference/react/use */
[@mel.module "react"] external usePromise: Js.Promise.t('a) => 'a = "use";
[@mel.module "react"] external useContext: Context.t('a) => 'a = "use";
/* https://react.dev/reference/react/useTransition */
[@mel.module "react"]
external useTransitionAsync:
unit => (bool, callbackAsync(callbackAsync(unit, unit), unit)) =
"useTransition";

/* https://es.react.dev/reference/react/useOptimistic */
/* https://react.dev/reference/react/useOptimistic */
[@mel.module "react"]
external useOptimistic:
('state, ('state, 'optimisticValue) => 'state) =>
Expand Down
2 changes: 1 addition & 1 deletion src/ReactDOM.re
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ type domProps = {
[@mel.optional]
acceptCharset: option(string),
[@mel.optional]
action: option(string),
action: option(string), /* uri */
[@mel.optional]
allowFullScreen: option(bool),
[@mel.optional]
Expand Down
99 changes: 91 additions & 8 deletions src/ReactDOMTestUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let undefined: undefined = Js.Undefined.empty;
[@mel.module "react"]
external reactAct: ((. unit) => undefined) => unit = "act";

[@deprecated "use React.act instead"]
let act: (unit => unit) => unit =
func => {
let reactFunc =
Expand All @@ -19,6 +20,7 @@ let act: (unit => unit) => unit =
external reactActAsync: ((. unit) => Js.Promise.t('a)) => Js.Promise.t(unit) =
"act";

[@deprecated "use React.actAsync instead"]
let actAsync = func => {
let reactFunc =
(.) => {
Expand All @@ -27,35 +29,73 @@ let actAsync = func => {
reactActAsync(reactFunc);
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isElement: 'element => bool = "isElement";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isElementOfType: ('element, React.component('props)) => bool =
"isElementOfType";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isDOMComponent: 'element => bool = "isDOMComponent";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isCompositeComponent: 'element => bool = "isCompositeComponent";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isCompositeComponentWithType:
('element, React.component('props)) => bool =
"isCompositeComponentWithType";

module Simulate = {
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external click: Dom.element => unit = "click";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external clickWithEvent: (Dom.element, 'event) => unit = "click";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external change: Dom.element => unit = "change";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external blur: Dom.element => unit = "blur";

[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
external changeWithEvent: (Dom.element, 'event) => unit = "change";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let changeWithValue = (element, value) => {
let event = {
"target": {
Expand All @@ -64,6 +104,10 @@ module Simulate = {
};
changeWithEvent(element, event);
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let changeWithChecked = (element, value) => {
let event = {
"target": {
Expand All @@ -72,11 +116,23 @@ module Simulate = {
};
changeWithEvent(element, event);
};
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external canPlay: Dom.element => unit = "canPlay";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external timeUpdate: Dom.element => unit = "timeUpdate";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external ended: Dom.element => unit = "ended";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
external focus: Dom.element => unit = "focus";
Expand All @@ -101,7 +157,9 @@ external body: Dom.document => option(Dom.element) = "body";
[@mel.send]
external createElement: (Dom.document, string) => Dom.element =
"createElement";

[@mel.send] external remove: Dom.element => unit = "remove";

[@mel.send]
external appendChild: (Dom.element, Dom.element) => Dom.element =
"appendChild";
Expand All @@ -111,38 +169,63 @@ let querySelectorAll = (element, string) => {
};

module DOM = {
[@mel.return nullable] [@mel.get]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
[@mel.return nullable]
[@mel.get]
external value: Dom.element => option(string) = "value";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
let findBySelector = (element, selector) =>
querySelector(element, selector);

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
let findByAllSelector = (element, selector) =>
querySelectorAll(element, selector);

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
let findBySelectorAndTextContent = (element, selector, content) =>
querySelectorAll(element, selector)
|> Array.find_opt(node => node->textContent === content);

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
let findBySelectorAndPartialTextContent = (element, selector, content) =>
querySelectorAll(element, selector)
|> Array.find_opt(node =>
Js.String.includes(~search=content, node->textContent)
);
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let prepareContainer = (container: ref(option(Dom.element)), ()) => {
let containerElement = document->createElement("div");
let _: option(_) =
Option.map(body => body->appendChild(containerElement), document->body);
container := Some(containerElement);
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let cleanupContainer = (container: ref(option(Dom.element)), ()) => {
let _: option(_) = Option.map(remove, container^);
container := None;
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let getContainer = container => {
container.contents->Option.get;
};
117 changes: 101 additions & 16 deletions src/ReactDOMTestUtils.rei
Original file line number Diff line number Diff line change
@@ -1,60 +1,145 @@
let act: (unit => unit) => unit;
let act: [@deprecated "use React.act instead"] ((unit => unit) => unit);

let actAsync: (unit => Js.Promise.t('a)) => Js.Promise.t(unit);
let actAsync:
[@deprecated "use React.actAsync instead"] (
(unit => Js.Promise.t('a)) => Js.Promise.t(unit)
);

[@mel.module "react-dom/test-utils"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
external isElement: 'element => bool = "isElement";

[@mel.module "react-dom/test-utils"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
external isElementOfType: ('element, React.component('props)) => bool =
"isElementOfType";

[@mel.module "react-dom/test-utils"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
external isDOMComponent: 'element => bool = "isDOMComponent";

[@mel.module "react-dom/test-utils"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
external isCompositeComponent: 'element => bool = "isCompositeComponent";

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
external isCompositeComponentWithType:
('element, React.component('props)) => bool =
"isCompositeComponentWithType";

module Simulate: {
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external click: Dom.element => unit = "click";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external clickWithEvent: (Dom.element, 'event) => unit = "click";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external change: Dom.element => unit = "change";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external blur: Dom.element => unit = "blur";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external changeWithEvent: (Dom.element, 'event) => unit = "change";
let changeWithValue: (Dom.element, string) => unit;
let changeWithChecked: (Dom.element, bool) => unit;
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external canPlay: Dom.element => unit = "canPlay";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external timeUpdate: Dom.element => unit = "timeUpdate";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external ended: Dom.element => unit = "ended";
[@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
[@mel.module "react-dom/test-utils"]
[@mel.scope "Simulate"]
external focus: Dom.element => unit = "focus";
};

module DOM: {
[@mel.return nullable] [@mel.get]
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
]
[@mel.return nullable]
[@mel.get]
external value: Dom.element => option(string) = "value";

let findBySelector: (Dom.element, string) => option(Dom.element);
let findByAllSelector: (Dom.element, string) => array(Dom.element);
let findBySelector:
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
] (
(Dom.element, string) => option(Dom.element)
);
let findByAllSelector:
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
] (
(Dom.element, string) => array(Dom.element)
);
let findBySelectorAndTextContent:
(Dom.element, string, string) => option(Dom.element);
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
] (
(Dom.element, string, string) => option(Dom.element)
);
let findBySelectorAndPartialTextContent:
(Dom.element, string, string) => option(Dom.element);
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead."
] (
(Dom.element, string, string) => option(Dom.element)
);
};

[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let prepareContainer: (Stdlib.ref(option(Dom.element)), unit) => unit;
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let cleanupContainer: (Stdlib.ref(option(Dom.element)), unit) => unit;
[@deprecated
"ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead."
]
let getContainer: Stdlib.ref(option(Dom.element)) => Dom.element;
Loading

0 comments on commit f7d55fe

Please sign in to comment.