Skip to content

Instantly share code, notes, and snippets.

@kt3k
Created June 1, 2021 04:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kt3k/f1975da5533bd567c1b363ccaec2cf69 to your computer and use it in GitHub Desktop.
Save kt3k/f1975da5533bd567c1b363ccaec2cf69 to your computer and use it in GitHub Desktop.
import "https://unpkg.com/react@17.0.2/umd/react.development.js";
import "https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js";
import "https://unpkg.com/@testing-library/react@11.2.7/dist/@testing-library/react.umd.js";
import jsdom from "https://dev.jspm.io/jsdom";
import { assert } from "https://deno.land/std@0.97.0/testing/asserts.ts";
const { render } = TestingLibraryReact; // <- Umd testing-library exports this in global
Deno.test("test", async () => {
const { JSDOM } = jsdom;
const doc = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
globalThis.document = doc.window.document;
globalThis.HTMLIFrameElement = doc.window.HTMLIFrameElement; // Needed for testing-library
const { getByText } = render(<div>hello</div>);
assert(getByText("hello") instanceof doc.window.HTMLDivElement);
// Needs to wait a little bit to prevent the leaking of the timer.
await new Promise(r => setTimeout(r, 10));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment