Skip to content

Commit 7258737

Browse files
committed
Also pass props to deferFn, as it does for promiseFn.
1 parent 3e2db9a commit 7258737

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const createInstance = (defaultProps = {}) => {
7171
this.counter++
7272
this.args = args
7373
this.setState({ isLoading: true, startedAt: new Date(), finishedAt: undefined })
74-
return deferFn(...args).then(this.onResolve(this.counter), this.onReject(this.counter))
74+
return deferFn(...args, this.props).then(this.onResolve(this.counter), this.onReject(this.counter))
7575
}
7676

7777
cancel = () => {

src/spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ test("re-runs the promise when the value of 'watch' changes", () => {
117117
expect(promiseFn).toHaveBeenCalledTimes(3)
118118
})
119119

120-
test("runs deferFn only when explicitly invoked, passing arguments", () => {
120+
test("runs deferFn only when explicitly invoked, passing arguments and props", () => {
121121
let counter = 1
122122
const deferFn = jest.fn().mockReturnValue(resolveTo())
123123
const { getByText } = render(
124-
<Async deferFn={deferFn}>
124+
<Async deferFn={deferFn} foo="bar">
125125
{({ run }) => {
126126
return <button onClick={() => run("go", counter++)}>run</button>
127127
}}
128128
</Async>
129129
)
130130
expect(deferFn).not.toHaveBeenCalled()
131131
fireEvent.click(getByText("run"))
132-
expect(deferFn).toHaveBeenCalledWith("go", 1)
132+
expect(deferFn).toHaveBeenCalledWith("go", 1, expect.objectContaining({ deferFn, foo: "bar" }))
133133
fireEvent.click(getByText("run"))
134-
expect(deferFn).toHaveBeenCalledWith("go", 2)
134+
expect(deferFn).toHaveBeenCalledWith("go", 2, expect.objectContaining({ deferFn, foo: "bar" }))
135135
})
136136

137137
test("reload uses the arguments of the previous run", () => {
@@ -151,11 +151,11 @@ test("reload uses the arguments of the previous run", () => {
151151
)
152152
expect(deferFn).not.toHaveBeenCalled()
153153
fireEvent.click(getByText("run"))
154-
expect(deferFn).toHaveBeenCalledWith("go", 1)
154+
expect(deferFn).toHaveBeenCalledWith("go", 1, expect.objectContaining({ deferFn }))
155155
fireEvent.click(getByText("run"))
156-
expect(deferFn).toHaveBeenCalledWith("go", 2)
156+
expect(deferFn).toHaveBeenCalledWith("go", 2, expect.objectContaining({ deferFn }))
157157
fireEvent.click(getByText("reload"))
158-
expect(deferFn).toHaveBeenCalledWith("go", 2)
158+
expect(deferFn).toHaveBeenCalledWith("go", 2, expect.objectContaining({ deferFn }))
159159
})
160160

161161
test("only accepts the last invocation of the promise", async () => {

0 commit comments

Comments
 (0)