Skip to content

Commit f59a490

Browse files
committed
Add missing imports for tests
1 parent 26f717a commit f59a490

File tree

8 files changed

+47
-63
lines changed

8 files changed

+47
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The best option is to check out our [integration tests](./src/tests-functional-c
1414
```typescript
1515
import { render } from "@testing-library/react";
1616
import React from "react";
17-
import { it, jest } from "@jest/globals";
17+
import { it, jest, expect, afterEach } from "@jest/globals";
1818
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
1919

2020
// Step 1: if using typescript, import the Prop types for the child component

src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file contains some basic tests, for the integration tests see `tests-class-component` and `tests-function-component`
22

3-
import { describe, it } from "@jest/globals";
3+
import { describe, expect, it } from "@jest/globals";
44
import "@testing-library/jest-dom";
55
import { render } from "@testing-library/react";
66
import React from "react";
@@ -68,7 +68,7 @@ describe("getMockComponentPropCalls", () => {
6868
expect(() => {
6969
getMockComponentPropCalls(
7070
// @ts-expect-error I'm testing a negative scenario here so I need to break typescript a bit
71-
() => React.createElement("span")
71+
() => React.createElement("span"),
7272
);
7373
}).toThrowError("Did you forget to call createMockComponent");
7474
});

src/tests-class-component/child-with-children/index.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { it, jest } from "@jest/globals";
1+
import { afterEach, describe, expect, it, jest } from "@jest/globals";
22
import "@testing-library/jest-dom";
3-
// https://github.com/testing-library/user-event/issues/1146: userEvent doesn't support Node16 properly
4-
const userEvent = UserEventModule.default ?? UserEventModule;
53
import { act, render } from "@testing-library/react";
6-
import UserEventModule from "@testing-library/user-event";
4+
import { userEvent } from "@testing-library/user-event";
75
import React from "react";
86
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
97

@@ -82,11 +80,10 @@ describe("Arrangeivating the onClick callback directly", () => {
8280
const result = render(<Parent />);
8381

8482
// Act
85-
await act(
86-
() =>
87-
getMockComponentPropCalls(Child)
88-
?.at(-1)
89-
?.onClick?.({} as any),
83+
await act(() =>
84+
getMockComponentPropCalls(Child)
85+
?.at(-1)
86+
?.onClick?.({} as any),
9087
);
9188

9289
// Assert
@@ -99,11 +96,10 @@ describe("Arrangeivating the onClick callback directly", () => {
9996
render(<Parent />);
10097

10198
// Act
102-
await act(
103-
() =>
104-
getMockComponentPropCalls(Child)
105-
?.at(-1)
106-
?.onClick?.({} as any),
99+
await act(() =>
100+
getMockComponentPropCalls(Child)
101+
?.at(-1)
102+
?.onClick?.({} as any),
107103
);
108104

109105
// Assert

src/tests-class-component/child-with-props/index.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { it, jest } from "@jest/globals";
1+
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
22
import "@testing-library/jest-dom";
3-
// https://github.com/testing-library/user-event/issues/1146: userEvent doesn't support Node16 properly
4-
const userEvent = UserEventModule.default ?? UserEventModule;
53
import { act, render } from "@testing-library/react";
6-
import UserEventModule from "@testing-library/user-event";
4+
import { userEvent } from "@testing-library/user-event";
75
import React from "react";
86
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
97

@@ -102,11 +100,10 @@ describe("Activating the onClick callback directly", () => {
102100
const result = render(<Parent />);
103101

104102
// Act
105-
await act(
106-
() =>
107-
getMockComponentPropCalls(Child)
108-
?.at(-1)
109-
?.onClick?.({} as any),
103+
await act(() =>
104+
getMockComponentPropCalls(Child)
105+
?.at(-1)
106+
?.onClick?.({} as any),
110107
);
111108

112109
// Assert
@@ -119,11 +116,10 @@ describe("Activating the onClick callback directly", () => {
119116
render(<Parent />);
120117

121118
// Act
122-
await act(
123-
() =>
124-
getMockComponentPropCalls(Child)
125-
?.at(-1)
126-
?.onClick?.({} as any),
119+
await act(() =>
120+
getMockComponentPropCalls(Child)
121+
?.at(-1)
122+
?.onClick?.({} as any),
127123
);
128124

129125
// Assert

src/tests-class-component/child-without-props/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { afterEach, expect, it, jest } from "@jest/globals";
2+
import "@testing-library/jest-dom";
13
import { render } from "@testing-library/react";
24
import React from "react";
3-
import { it, jest } from "@jest/globals";
45
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
5-
import "@testing-library/jest-dom";
66

77
// Step 1:
88
// import type allows you to import just the types and not the actual file.

src/tests-functional-component/child-with-children/index.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { it, jest } from "@jest/globals";
1+
import { afterEach, describe, expect, it, jest } from "@jest/globals";
22
import "@testing-library/jest-dom";
3-
// https://github.com/testing-library/user-event/issues/1146: userEvent doesn't support Node16 properly
4-
const userEvent = UserEventModule.default ?? UserEventModule;
53
import { act, render } from "@testing-library/react";
6-
import UserEventModule from "@testing-library/user-event";
4+
import { userEvent } from "@testing-library/user-event";
75
import React from "react";
86
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
97

@@ -82,11 +80,10 @@ describe("Arrangeivating the onClick callback directly", () => {
8280
const result = render(<Parent />);
8381

8482
// Act
85-
await act(
86-
() =>
87-
getMockComponentPropCalls(Child)
88-
?.at(-1)
89-
?.onClick?.({} as any),
83+
await act(() =>
84+
getMockComponentPropCalls(Child)
85+
?.at(-1)
86+
?.onClick?.({} as any),
9087
);
9188

9289
// Assert
@@ -99,11 +96,10 @@ describe("Arrangeivating the onClick callback directly", () => {
9996
render(<Parent />);
10097

10198
// Act
102-
await act(
103-
() =>
104-
getMockComponentPropCalls(Child)
105-
?.at(-1)
106-
?.onClick?.({} as any),
99+
await act(() =>
100+
getMockComponentPropCalls(Child)
101+
?.at(-1)
102+
?.onClick?.({} as any),
107103
);
108104

109105
// Assert

src/tests-functional-component/child-with-props/index.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { it, jest } from "@jest/globals";
1+
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
22
import "@testing-library/jest-dom";
3-
// https://github.com/testing-library/user-event/issues/1146: userEvent doesn't support Node16 properly
4-
const userEvent = UserEventModule.default ?? UserEventModule;
53
import { act, render } from "@testing-library/react";
6-
import UserEventModule from "@testing-library/user-event";
4+
import { userEvent } from "@testing-library/user-event";
75
import React from "react";
86
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
97

@@ -102,11 +100,10 @@ describe("Activating the onClick callback directly", () => {
102100
const result = render(<Parent />);
103101

104102
// Act
105-
await act(
106-
() =>
107-
getMockComponentPropCalls(Child)
108-
?.at(-1)
109-
?.onClick?.({} as any),
103+
await act(() =>
104+
getMockComponentPropCalls(Child)
105+
?.at(-1)
106+
?.onClick?.({} as any),
110107
);
111108

112109
// Assert
@@ -119,11 +116,10 @@ describe("Activating the onClick callback directly", () => {
119116
render(<Parent />);
120117

121118
// Act
122-
await act(
123-
() =>
124-
getMockComponentPropCalls(Child)
125-
?.at(-1)
126-
?.onClick?.({} as any),
119+
await act(() =>
120+
getMockComponentPropCalls(Child)
121+
?.at(-1)
122+
?.onClick?.({} as any),
127123
);
128124

129125
// Assert

src/tests-functional-component/child-without-props/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { afterEach, expect, it, jest } from "@jest/globals";
2+
import "@testing-library/jest-dom";
13
import { render } from "@testing-library/react";
24
import React from "react";
3-
import { it, jest } from "@jest/globals";
45
import { createMockComponent, getMockComponentPropCalls } from "../../index.js";
5-
import "@testing-library/jest-dom";
66

77
// Step 1:
88
// import type allows you to import just the types and not the actual file.

0 commit comments

Comments
 (0)