Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Fixed a case with merging request options in Poll
Browse files Browse the repository at this point in the history
  • Loading branch information
vxsx committed Apr 8, 2019
1 parent 041a3a8 commit 1914b50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/Poll.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,5 +678,26 @@ describe("Poll", () => {
expect(children.mock.calls[1][1].loading).toEqual(false);
expect(children.mock.calls[1][0]).toEqual({ id: 1 });
});

it("should merge headers with providers", async () => {
nock("https://my-awesome-api.fake", { reqheaders: { foo: "bar", baz: "qux" } })
.get("/")
.reply(200, { id: 1 });

const children = jest.fn();
children.mockReturnValue(<div />);

render(
<RestfulProvider base="https://my-awesome-api.fake" requestOptions={{ headers: { baz: "qux" } }}>
<Poll path="" requestOptions={() => ({ headers: { foo: "bar" } })}>
{children}
</Poll>
</RestfulProvider>,
);

await wait(() => expect(children.mock.calls.length).toBe(2));
expect(children.mock.calls[1][1].loading).toEqual(false);
expect(children.mock.calls[1][0]).toEqual({ id: 1 });
});
});
});
6 changes: 2 additions & 4 deletions src/Poll.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import merge from "lodash/merge";
import * as qs from "qs";
import * as React from "react";
import equal from "react-fast-compare";
Expand Down Expand Up @@ -351,10 +352,7 @@ function Poll<TData = any, TError = any, TQueryParams = { [key: string]: any }>(
<ContextlessPoll
{...contextProps}
{...props}
requestOptions={{
...contextRequestOptions,
...propsRequestOptions,
}}
requestOptions={merge(contextRequestOptions, propsRequestOptions)}
/>
);
}}
Expand Down

0 comments on commit 1914b50

Please sign in to comment.