Skip to content

Commit 7c3da2a

Browse files
committed
Add tests to examples.
1 parent 5f90a7f commit 7c3da2a

File tree

13 files changed

+82
-15
lines changed

13 files changed

+82
-15
lines changed

examples/basic-fetch/src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const UserDetails = ({ data }) => (
2525
</div>
2626
)
2727

28-
const App = () => (
28+
export const App = () => (
2929
<>
3030
<DevTools />
3131
<Async promiseFn={loadUser} userId={1} debugLabel="User 1">
@@ -47,4 +47,4 @@ const App = () => (
4747
</>
4848
)
4949

50-
ReactDOM.render(<App />, document.getElementById("root"))
50+
if (process.env.NODE_ENV !== "test") ReactDOM.render(<App />, document.getElementById("root"))
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import { App } from "./"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

examples/basic-hook/src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ const User = ({ userId }) => {
3838
return null
3939
}
4040

41-
const App = () => (
41+
export const App = () => (
4242
<>
4343
<DevTools />
4444
<User userId={1} />
4545
<User userId={2} />
4646
</>
4747
)
4848

49-
ReactDOM.render(<App />, document.getElementById("root"))
49+
if (process.env.NODE_ENV !== "test") ReactDOM.render(<App />, document.getElementById("root"))

examples/basic-hook/src/index.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import { App } from "./"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

examples/custom-instance/src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const UserDetails = ({ data }) => (
2727
</div>
2828
)
2929

30-
const App = () => (
30+
export const App = () => (
3131
<>
3232
<DevTools />
3333
<AsyncUser userId={1} debugLabel="User 1">
@@ -48,4 +48,4 @@ const App = () => (
4848
</>
4949
)
5050

51-
ReactDOM.render(<App />, document.getElementById("root"))
51+
if (process.env.NODE_ENV !== "test") ReactDOM.render(<App />, document.getElementById("root"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import { App } from "./"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

examples/movie-app/src/App.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import App from "./App"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

examples/with-abortcontroller/src/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const download = (args, props, controller) =>
99
.then(res => (res.ok ? res : Promise.reject(res)))
1010
.then(res => res.json())
1111

12-
const App = () => {
12+
export const App = () => {
1313
const { run, cancel, isPending } = useAsync({ deferFn: download, debugLabel: "User 1" })
1414
return (
1515
<>
@@ -23,10 +23,11 @@ const App = () => {
2323
)
2424
}
2525

26-
ReactDOM.render(
27-
<>
28-
<DevTools />
29-
<App />
30-
</>,
31-
document.getElementById("root")
32-
)
26+
if (process.env.NODE_ENV !== "test")
27+
ReactDOM.render(
28+
<>
29+
<DevTools />
30+
<App />
31+
</>,
32+
document.getElementById("root")
33+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import { App } from "./"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

examples/with-react-router/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"postinstall": "relative-deps",
88
"prestart": "relative-deps",
9-
"pretest": "relative-deps",
109
"start": "parcel index.html"
1110
},
1211
"dependencies": {

examples/with-typescript/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"typescript": "^3.5.1"
2424
},
2525
"devDependencies": {
26+
"@types/jest": "^24.0.15",
2627
"relative-deps": "^0.1.2"
2728
},
2829
"relativeDependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
import App from "./App"
4+
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div")
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,18 @@
30483048
"@types/istanbul-lib-coverage" "*"
30493049
"@types/istanbul-lib-report" "*"
30503050

3051+
"@types/jest-diff@*":
3052+
version "20.0.1"
3053+
resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89"
3054+
integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==
3055+
3056+
"@types/jest@^24.0.15":
3057+
version "24.0.15"
3058+
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.15.tgz#6c42d5af7fe3b44ffff7cc65de7bf741e8fa427f"
3059+
integrity sha512-MU1HIvWUme74stAoc3mgAi+aMlgKOudgEvQDIm1v4RkrDudBh1T+NFp5sftpBAdXdx1J0PbdpJ+M2EsSOi1djA==
3060+
dependencies:
3061+
"@types/jest-diff" "*"
3062+
30513063
"@types/minimatch@*":
30523064
version "3.0.3"
30533065
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"

0 commit comments

Comments
 (0)