-
Notifications
You must be signed in to change notification settings - Fork 2
/
global-jsdom.ts
41 lines (40 loc) · 1.38 KB
/
global-jsdom.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* This module is used to setup the jsdom environment for the tests.
* This module should be imported before importing react testing library.
* If you do not import this file before importing react testing library,
* you will get an error when calling any of the screen functions.
*
* ```ts
* import { assertEquals } from "@std/assert";
* import { describe, it } from "@std/testing/bdd";
* import "@udibo/react-app/global-jsdom";
* import { cleanup, render, screen } from "@testing-library/react";
*
* const loadingTests = describe({
* name: "Loading",
* afterEach() {
* cleanup();
* },
* });
*
* it(loadingTests, "renders loading message", () => {
* render(<Loading />);
* assertEquals(screen.getByText("Loading...").textContent, "Loading...");
* });
* ```
*
* If the default jsdom options do not work for your usecase, you can create your own `global-jsdom.ts` file to use instead of this module.
* Just replace the html and options arguments in the following example with your own values.
*
* ```ts
* import jsdom from "global-jsdom";
* jsdom(html, options);
* ```
*
* Then in your test files, do `import "./global-jsdom.js";` instead of `import "@udibo/react-app/global-jsdom";` before importing react testing library.
* The path to the `global-jsdom.js` file should be relative to the test file.
*
* @module
*/
import jsdom from "global-jsdom";
jsdom();