-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathfetch-globals-test.ts
42 lines (36 loc) · 1.18 KB
/
fetch-globals-test.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
42
import { test, expect } from "@playwright/test";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
createFixture,
js,
} from "./helpers/create-fixture.js";
let fixture: Fixture;
let appFixture: AppFixture;
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/routes/_index.tsx": js`
import { useLoaderData } from "react-router";
export async function loader() {
const resp = await fetch('https://reqres.in/api/users?page=2');
return (resp instanceof Response) ? 'is an instance of global Response' : 'is not an instance of global Response';
}
export default function Index() {
let data = useLoaderData();
return (
<div>
{data}
</div>
)
}
`,
},
});
appFixture = await createAppFixture(fixture);
});
test.afterAll(async () => appFixture.close());
test("returned variable from fetch() should be instance of global Response", async () => {
let response = await fixture.requestDocument("/");
expect(await response.text()).toMatch("is an instance of global Response");
});