Skip to content

Commit

Permalink
Applied suggestions from PR#104
Browse files Browse the repository at this point in the history
  • Loading branch information
NSeydoux committed Jun 2, 2020
1 parent 07d093b commit eb29a5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/nonRdfData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Headers, Response } from "cross-fetch";

describe("Non-RDF data fetch", () => {
it("should GET a remote resource using cross-fetch if no other fetcher is available", async () => {
// Mocking cross-fetch must not happen in the global scope, otherwise it
// breaks the imports of the Headers and Response classes.
jest.mock("cross-fetch");
const crossFetch = jest.requireMock("cross-fetch") as jest.Mock<
ReturnType<typeof window.fetch>,
Expand All @@ -22,7 +24,7 @@ describe("Non-RDF data fetch", () => {
[
"https://some.url",
{
headers: new Headers({}),
headers: {},
},
],
]);
Expand All @@ -43,7 +45,7 @@ describe("Non-RDF data fetch", () => {
[
"https://some.url",
{
headers: new Headers({}),
headers: {},
},
],
]);
Expand Down
16 changes: 8 additions & 8 deletions src/nonRdfData.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fetch } from "./fetcher";
import { IriString } from "./index";
import { Headers } from "cross-fetch";

/**
* @internal
*/
const defaultFetchOptions = {
headers: new Headers({}),
interface GetFileOptions {
fetch: typeof window.fetch;
headers: RequestInit["headers"];
}
const defaultGetFileOptions = {
headers: {},
fetch: fetch,
};

Expand All @@ -18,10 +18,10 @@ const defaultFetchOptions = {
*/
export async function getFile(
url: IriString,
options: Partial<typeof defaultFetchOptions> = defaultFetchOptions
options: Partial<GetFileOptions> = defaultGetFileOptions
): Promise<Blob> {
const config = {
...defaultFetchOptions,
...defaultGetFileOptions,
...options,
};
const response = await config.fetch(url, { headers: config.headers });
Expand Down

0 comments on commit eb29a5f

Please sign in to comment.