Skip to content

Commit

Permalink
Remove outdated workarounds
Browse files Browse the repository at this point in the history
With the release of a new Jest version with a fix for
jestjs/jest#10600, a lot of type
assertions in tests are no longer necessary.
  • Loading branch information
Vinnl committed Oct 6, 2020
1 parent 74b94da commit f0e99c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 71 deletions.
18 changes: 3 additions & 15 deletions src/acp/policy.test.ts
Expand Up @@ -56,11 +56,7 @@ const policyUrl = "https://some.pod/policy-resource";

describe("savePolicyDatasetAt", () => {
it("sets the type of acp:AccessPolicy if not set yet", async () => {
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(new Response() as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(new Response());
const newDataset = createSolidDataset();

const savedDataset = await savePolicyDatasetAt(policyUrl, newDataset, {
Expand All @@ -73,11 +69,7 @@ describe("savePolicyDatasetAt", () => {
});

it("overwrites an existing type that might be set", async () => {
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(new Response() as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(new Response());
let newDatasetThing = createThing({ url: policyUrl });
newDatasetThing = setUrl(
newDatasetThing,
Expand Down Expand Up @@ -111,11 +103,7 @@ describe("savePolicyDatasetAt", () => {
});

it("uses the given fetcher if provided", async () => {
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(new Response() as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(new Response());

await savePolicyDatasetAt(policyUrl, createSolidDataset(), {
fetch: mockFetch,
Expand Down
6 changes: 2 additions & 4 deletions src/resource/nonRdfData.test.ts
Expand Up @@ -490,10 +490,8 @@ describe("Write non-RDF data into a folder", () => {
} as ResponseInit)
): MockFetch {
fetch
// The type assertions to any are necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
.mockResolvedValueOnce(saveResponse as any)
.mockResolvedValueOnce(headResponse as any);
.mockResolvedValueOnce(saveResponse)
.mockResolvedValueOnce(headResponse);
return fetch;
}

Expand Down
10 changes: 2 additions & 8 deletions src/resource/resource.test.ts
Expand Up @@ -529,9 +529,7 @@ describe("getResourceInfo", () => {
const mockFetch = jest.fn(window.fetch).mockResolvedValue(
mockResponse(undefined, {
url: "https://arbitrary.pod",
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
}) as any
})
);

const solidDatasetInfo = await getResourceInfo(
Expand All @@ -551,11 +549,7 @@ describe("getResourceInfo", () => {
// We need the type assertion because in non-mock situations,
// you cannot set the URL manually:
} as ResponseInit);
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(mockResponse as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(mockResponse);

const solidDatasetInfo = await getResourceInfo(
"https://some.pod/container/resource",
Expand Down
72 changes: 28 additions & 44 deletions src/resource/solidDataset.test.ts
Expand Up @@ -177,11 +177,7 @@ describe("getSolidDataset", () => {
// We need the type assertion because in non-mock situations,
// you cannot set the URL manually:
} as ResponseInit);
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(mockResponse as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(mockResponse);

const solidDataset = await getSolidDataset(
"https://some.pod/container/resource",
Expand Down Expand Up @@ -1050,11 +1046,11 @@ describe("deleteSolidDataset", () => {
});

it("should DELETE a remote SolidDataset using the provided fetcher", async () => {
const mockFetch = jest.fn(window.fetch).mockResolvedValue(
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
new Response(undefined, { status: 200, statusText: "Deleted" }) as any
);
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(
new Response(undefined, { status: 200, statusText: "Deleted" })
);

const response = await deleteSolidDataset("https://some.url", {
fetch: mockFetch,
Expand All @@ -1072,11 +1068,11 @@ describe("deleteSolidDataset", () => {
});

it("should accept a fetched SolidDataset as target", async () => {
const mockFetch = jest.fn(window.fetch).mockResolvedValue(
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
new Response(undefined, { status: 200, statusText: "Deleted" }) as any
);
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(
new Response(undefined, { status: 200, statusText: "Deleted" })
);

const mockSolidDataset = mockSolidDatasetFrom("https://some.url");

Expand All @@ -1100,9 +1096,7 @@ describe("deleteSolidDataset", () => {
new Response(undefined, {
status: 400,
statusText: "Bad request",
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
}) as any
})
);

const deletionPromise = deleteSolidDataset("https://some.url", {
Expand Down Expand Up @@ -1247,11 +1241,7 @@ describe("createContainerAt", () => {
// We need the type assertion because in non-mock situations,
// you cannot set the URL manually:
} as ResponseInit);
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(mockResponse as any);
const mockFetch = jest.fn(window.fetch).mockResolvedValue(mockResponse);

const solidDataset = await createContainerAt(
"https://some.pod/container/",
Expand Down Expand Up @@ -1595,10 +1585,8 @@ describe("saveSolidDatasetInContainer", () => {
} as ResponseInit)
): MockFetch {
fetch
// The type assertions to any are necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
.mockResolvedValueOnce(saveResponse as any)
.mockResolvedValueOnce(headResponse as any);
.mockResolvedValueOnce(saveResponse)
.mockResolvedValueOnce(headResponse);
return fetch;
}

Expand Down Expand Up @@ -1958,10 +1946,8 @@ describe("createContainerInContainer", () => {
} as ResponseInit)
): MockFetch {
fetch
// The type assertions to any are necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
.mockResolvedValueOnce(saveResponse as any)
.mockResolvedValueOnce(headResponse as any);
.mockResolvedValueOnce(saveResponse)
.mockResolvedValueOnce(headResponse);
return fetch;
}

Expand Down Expand Up @@ -2246,11 +2232,11 @@ describe("deleteContainer", () => {
});

it("should DELETE a remote Container using the provided fetcher", async () => {
const mockFetch = jest.fn(window.fetch).mockResolvedValue(
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
new Response(undefined, { status: 200, statusText: "Deleted" }) as any
);
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(
new Response(undefined, { status: 200, statusText: "Deleted" })
);

const response = await deleteContainer("https://some.pod/container/", {
fetch: mockFetch,
Expand All @@ -2268,11 +2254,11 @@ describe("deleteContainer", () => {
});

it("should accept a fetched Container as target", async () => {
const mockFetch = jest.fn(window.fetch).mockResolvedValue(
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
new Response(undefined, { status: 200, statusText: "Deleted" }) as any
);
const mockFetch = jest
.fn(window.fetch)
.mockResolvedValue(
new Response(undefined, { status: 200, statusText: "Deleted" })
);

const mockContainer = mockSolidDatasetFrom("https://some.pod/container/");

Expand Down Expand Up @@ -2305,9 +2291,7 @@ describe("deleteContainer", () => {
new Response(undefined, {
status: 400,
statusText: "Bad request",
// The type assertion to any is necessary due to invalid Jest type definitions:
// https://github.com/facebook/jest/pull/10600
}) as any
})
);

const deletionPromise = deleteContainer("https://some.pod/container/", {
Expand Down

0 comments on commit f0e99c9

Please sign in to comment.