Skip to content

Commit c40d5d8

Browse files
committed
add tests for helpers with missing state
1 parent 306befa commit c40d5d8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/react-async/src/helpers.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ describe("IfFulfilled", () => {
8484
await findByText("outer inner")
8585
expect(queryByText("outer inner")).toBeInTheDocument()
8686
})
87-
87+
test("renders nothing if missing state", () => {
88+
const { queryByText } = render(<IfFulfilled>Test</IfFulfilled>)
89+
expect(queryByText("Test")).not.toBeInTheDocument()
90+
})
8891
test("renders without children", async () => {
8992
const promiseFn = () => resolveTo("ok")
9093
render(<Async promiseFn={promiseFn}>{state => <IfFulfilled state={state} />}</Async>)
@@ -109,6 +112,10 @@ describe("IfPending", () => {
109112
await findByText("done")
110113
expect(queryByText("pending")).toBeNull()
111114
})
115+
test("renders nothing if missing state", () => {
116+
const { queryByText } = render(<IfPending>Test</IfPending>)
117+
expect(queryByText("Test")).not.toBeInTheDocument()
118+
})
112119
})
113120

114121
describe("IfInitial", () => {
@@ -134,6 +141,10 @@ describe("IfInitial", () => {
134141
await findByText("done")
135142
expect(queryByText("pending")).toBeNull()
136143
})
144+
test("renders nothing if missing state", () => {
145+
const { queryByText } = render(<IfInitial>Test</IfInitial>)
146+
expect(queryByText("Test")).not.toBeInTheDocument()
147+
})
137148
})
138149

139150
describe("IfRejected", () => {
@@ -148,6 +159,10 @@ describe("IfRejected", () => {
148159
await findByText("err")
149160
expect(queryByText("err")).toBeInTheDocument()
150161
})
162+
test("renders nothing if missing state", () => {
163+
const { queryByText } = render(<IfRejected>Test</IfRejected>)
164+
expect(queryByText("Test")).not.toBeInTheDocument()
165+
})
151166
})
152167

153168
describe("IfSettled", () => {
@@ -197,4 +212,8 @@ describe("IfSettled", () => {
197212
fireEvent.click(getByText("reload"))
198213
await findByText("loading")
199214
})
215+
test("renders nothing if missing state", () => {
216+
const { queryByText } = render(<IfSettled>Test</IfSettled>)
217+
expect(queryByText("Test")).not.toBeInTheDocument()
218+
})
200219
})

0 commit comments

Comments
 (0)