summaryrefslogtreecommitdiff
path: root/std/types/tests
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-03-17 23:28:07 +1100
committerGitHub <noreply@github.com>2020-03-17 13:28:07 +0100
commit9050d36d5763beabb1a642819dd24d61cccb3ffe (patch)
treeb3c88e4c0964a4b3ea54642856a0fcbacd6017f7 /std/types/tests
parent9833975ef21afced84c6a16724ce13d026f09298 (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.js9
-rw-r--r--std/types/tests/react-dom_test.tsx20
-rw-r--r--std/types/tests/react_mock.js9
-rw-r--r--std/types/tests/react_test.tsx23
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":[]}`
+ );
+ }
+});