diff --git a/test/ReactDOMDataAttributes__test.re b/test/ReactDOMDataAttributes__test.re new file mode 100644 index 000000000..961a2bb1a --- /dev/null +++ b/test/ReactDOMDataAttributes__test.re @@ -0,0 +1,171 @@ +open Jest; +open Jest.Expect; + +[@mel.send] +external getAttribute: (Dom.element, string) => Js.nullable(string) = + "getAttribute"; + +/* Exercise React's data attribute behavior through the existing cloning API. + The JSX implementation can use the same assertions once it accepts data props. */ +describe("ReactDOM data attributes", () => { + test("renders data attributes alongside ordinary props", () => { + let html = + ReactDOMServer.renderToStaticMarkup( + React.cloneElement( +
+ {React.cloneElement(, { "data-foo-bar": "second" })} +
, + { + "data-test-id": "first", + "data-version2": "v2", + }, + ), + ); + expect(html) + ->toBe( + "
", + ); + }); + + test("omits absent optional attributes", () => { + let render = dataFoo => + ReactDOMServer.renderToStaticMarkup( + React.cloneElement( +
, + { "data-foo": Js.Undefined.fromOption(dataFoo) }, + ), + ); + expect(render(None))->toBe("
"); + expect(render(Some("value")))->toBe("
"); + }); + + test("updates and removes data attributes on the same DOM node", () => { + let element = (value, state) => + React.cloneElement( +