Skip to content

Commit

Permalink
Make use of @jest/globals
Browse files Browse the repository at this point in the history
This makes it easier for TypeScript to typecheck our tests, rather
relying on `any`-typed globals.

For more details, see
https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals

Unfortunately, it was not possible to
`import { jest } from "@jest/globals"` in files that also call
jest.mock(). This was reported here:
jestjs/jest#10060
  • Loading branch information
Vinnl committed May 25, 2020
1 parent 2cf0784 commit e49e933
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/datatypes.test.ts
@@ -1,3 +1,4 @@
import { describe, it, expect } from "@jest/globals";
import { DataFactory } from "n3";
import { LocalNode } from "./index";
import {
Expand Down
6 changes: 5 additions & 1 deletion src/fetcher.test.ts
@@ -1,9 +1,13 @@
import { it, expect } from "@jest/globals";
jest.mock("cross-fetch");

import { fetch } from "./fetcher";

it("should fallback to cross-fetch if no Solid-specific fetcher is available", async () => {
const crossFetch = jest.requireMock("cross-fetch");
const crossFetch = jest.requireMock("cross-fetch") as jest.Mock<
ReturnType<typeof window.fetch>,
[RequestInfo, RequestInit]
>;

await fetch("https://some.url");

Expand Down

0 comments on commit e49e933

Please sign in to comment.