Skip to content

Commit cd04330

Browse files
authored
fix: replace fireEvent with userEvent (#5361)
* fix: replace fireEvent with userEvent * fmt
1 parent 935d2eb commit cd04330

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fireEvent, screen, waitFor, within } from "@testing-library/react"
1+
import { screen, waitFor, within } from "@testing-library/react"
22
import userEvent from "@testing-library/user-event"
33
import EventSourceMock from "eventsourcemock"
44
import i18next from "i18next"
@@ -48,9 +48,11 @@ const renderWorkspacePage = async () => {
4848
* workspaceStatus was calculated correctly.
4949
*/
5050
const testButton = async (label: string, actionMock: jest.SpyInstance) => {
51+
const user = userEvent.setup()
52+
5153
await renderWorkspacePage()
5254
const button = await screen.findByRole("button", { name: label })
53-
fireEvent.click(button)
55+
await user.click(button)
5456
expect(actionMock).toBeCalled()
5557
}
5658

@@ -65,7 +67,7 @@ const testStatus = async (ws: Workspace, label: string) => {
6567
)
6668
await renderWorkspacePage()
6769
const header = screen.getByTestId("header")
68-
const status = await within(header).findByRole("status")
70+
const status = within(header).getByRole("status")
6971
expect(status).toHaveTextContent(label)
7072
}
7173

@@ -88,6 +90,7 @@ afterAll(() => {
8890
describe("WorkspacePage", () => {
8991
it("requests a delete job when the user presses Delete and confirms", async () => {
9092
const user = userEvent.setup()
93+
9194
const deleteWorkspaceMock = jest
9295
.spyOn(api, "deleteWorkspace")
9396
.mockResolvedValueOnce(MockWorkspaceBuild)
@@ -160,7 +163,7 @@ describe("WorkspacePage", () => {
160163
name: "cancel action",
161164
})
162165

163-
fireEvent.click(cancelButton)
166+
await userEvent.setup().click(cancelButton)
164167

165168
expect(cancelWorkspaceMock).toBeCalled()
166169
})
@@ -180,7 +183,7 @@ describe("WorkspacePage", () => {
180183
await renderWorkspacePage()
181184
const buttonText = t("actionButton.update", { ns: "workspacePage" })
182185
const button = await screen.findByText(buttonText, { exact: true })
183-
fireEvent.click(button)
186+
await userEvent.setup().click(button)
184187

185188
// getTemplate is called twice: once when the machine starts, and once after the user requests to update
186189
expect(getTemplateMock).toBeCalledTimes(2)
@@ -202,7 +205,7 @@ describe("WorkspacePage", () => {
202205
await renderWorkspacePage()
203206
const buttonText = t("actionButton.update", { ns: "workspacePage" })
204207
const button = await screen.findByText(buttonText, { exact: true })
205-
fireEvent.click(button)
208+
await userEvent.setup().click(button)
206209

207210
await waitFor(() =>
208211
expect(api.startWorkspace).toBeCalledWith(
@@ -211,6 +214,7 @@ describe("WorkspacePage", () => {
211214
),
212215
)
213216
})
217+
214218
it("shows the Stopping status when the workspace is stopping", async () => {
215219
await testStatus(
216220
MockStoppingWorkspace,

0 commit comments

Comments
 (0)