diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-03-17 23:28:07 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-17 13:28:07 +0100 |
commit | 9050d36d5763beabb1a642819dd24d61cccb3ffe (patch) | |
tree | b3c88e4c0964a4b3ea54642856a0fcbacd6017f7 /std/types/tests | |
parent | 9833975ef21afced84c6a16724ce13d026f09298 (diff) |
std: Provide types for React and ReactDOM (#4376)
Introduces `std/types` which is designed to provide types for common
libraries that are compatible with Deno.
Diffstat (limited to 'std/types/tests')
-rw-r--r-- | std/types/tests/react-dom_mock.js | 9 | ||||
-rw-r--r-- | std/types/tests/react-dom_test.tsx | 20 | ||||
-rw-r--r-- | std/types/tests/react_mock.js | 9 | ||||
-rw-r--r-- | std/types/tests/react_test.tsx | 23 |
4 files changed, 61 insertions, 0 deletions
diff --git a/std/types/tests/react-dom_mock.js b/std/types/tests/react-dom_mock.js new file mode 100644 index 000000000..68b4137ba --- /dev/null +++ b/std/types/tests/react-dom_mock.js @@ -0,0 +1,9 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +const ReactDOM = { + render(element) { + return JSON.stringify(element); + } +}; + +export default ReactDOM; diff --git a/std/types/tests/react-dom_test.tsx b/std/types/tests/react-dom_test.tsx new file mode 100644 index 000000000..738227b65 --- /dev/null +++ b/std/types/tests/react-dom_test.tsx @@ -0,0 +1,20 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +// @deno-types="../react.d.ts" +import React from "./react_mock.js"; +// @deno-types="../react-dom.d.ts" +import ReactDOM from "./react-dom_mock.js"; + +import { assertEquals } from "../../testing/asserts.ts"; + +const { test } = Deno; + +test({ + name: "ReactDOM is typed to render", + fn() { + assertEquals( + ReactDOM.render(<div />, null), + '"{\\"type\\":\\"div\\",\\"props\\":null,\\"children\\":[]}"' + ); + } +}); diff --git a/std/types/tests/react_mock.js b/std/types/tests/react_mock.js new file mode 100644 index 000000000..93faa6c9b --- /dev/null +++ b/std/types/tests/react_mock.js @@ -0,0 +1,9 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +const React = { + createElement(type, props, ...children) { + return JSON.stringify({ type, props, children }); + } +}; + +export default React; diff --git a/std/types/tests/react_test.tsx b/std/types/tests/react_test.tsx new file mode 100644 index 000000000..f9ffc471a --- /dev/null +++ b/std/types/tests/react_test.tsx @@ -0,0 +1,23 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +// @deno-types="../react.d.ts" +import React from "./react_mock.js"; +import { assertEquals } from "../../testing/asserts.ts"; + +const { test } = Deno; + +test({ + name: "JSX can be rendered", + fn() { + class Component { + render() { + return <div></div>; + } + } + + assertEquals( + new Component().render(), + `{"type":"div","props":null,"children":[]}` + ); + } +}); |