-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug tests: apparently, functions that are already async must *not* …
…be wrapped in act() - even if you await the call to act() and correctly await all the same things inside the callback, the timing for some reason will not work out as required, and it will somehow return before react finishes updates
- Loading branch information
Rasmus Schultz
committed
Aug 10, 2022
1 parent
bd4f76f
commit b70302f
Showing
3 changed files
with
27 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,14 +84,10 @@ describe(AuthorizedHome, () => { | |
|
||
const { findByLabelText, findByText } = renderPage() | ||
|
||
await act(async () => { | ||
await userEvent.type(await findByLabelText("Description"), "Description") | ||
await userEvent.type(await findByLabelText("E-mail"), "[email protected]") | ||
await userEvent.type(await findByLabelText("Phone"), "12345678") | ||
await userEvent.click(await findByText("Submit")) | ||
}) | ||
|
||
await findByText("1234"); // TODO find something we can wait for? | ||
await userEvent.type(await findByLabelText("Description"), "Description") | ||
await userEvent.type(await findByLabelText("E-mail"), "[email protected]") | ||
await userEvent.type(await findByLabelText("Phone"), "12345678") | ||
await userEvent.click(await findByText("Submit")) | ||
|
||
await waitFor(() => | ||
expect(mockedAxios.put).toHaveBeenCalledWith("/api/authorizedexample", { | ||
|
@@ -204,15 +200,14 @@ describe(AuthorizedHome, () => { | |
}) | ||
|
||
it("uses the right access token", async () => { | ||
const { findByText } = renderPage() | ||
|
||
// Wait for component to finish loading to prevent "not wrapped in act" error | ||
await findByText(entity.name) | ||
renderPage() | ||
|
||
const useHubParams = mockedUseHub.mock.calls[0] | ||
const [_path, _onConnected, connectionOptions] = useHubParams | ||
|
||
expect(connectionOptions.accessTokenFactory()).toEqual("1234") | ||
waitFor(() => { | ||
expect(connectionOptions.accessTokenFactory()).toEqual("1234") | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,47 +74,37 @@ describe(Home, () => { | |
|
||
const { getByLabelText, getByText, findAllByRole } = renderPage() | ||
|
||
await findAllByRole("table") // TODO remove this and everything blows up. I have no idea why. | ||
|
||
await act(async () => { | ||
await userEvent.type(getByLabelText("Name"), "Name") | ||
await userEvent.type(getByLabelText("Description"), "Description") | ||
await userEvent.type(getByLabelText("E-mail"), "[email protected]") | ||
await userEvent.type(getByLabelText("Phone"), "12345678") | ||
|
||
await userEvent.click(getByText("Submit")) | ||
|
||
await waitFor(() => | ||
expect(mockedAxios.put).toHaveBeenCalledWith("/api/example", { | ||
Name: "Name", | ||
Description: "Description", | ||
Email: "[email protected]", | ||
Phone: "12345678", | ||
}) | ||
) | ||
}) | ||
await userEvent.type(getByLabelText("Name"), "Name") | ||
await userEvent.type(getByLabelText("Description"), "Description") | ||
await userEvent.type(getByLabelText("E-mail"), "[email protected]") | ||
await userEvent.type(getByLabelText("Phone"), "12345678") | ||
|
||
await userEvent.click(getByText("Submit")) | ||
|
||
await waitFor(() => | ||
expect(mockedAxios.put).toHaveBeenCalledWith("/api/example", { | ||
Name: "Name", | ||
Description: "Description", | ||
Email: "[email protected]", | ||
Phone: "12345678", | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("when clicking remove ", () => { | ||
it("calls backend to remove", async () => { | ||
const { findAllByRole } = renderPage() | ||
|
||
await findAllByRole("table") // TODO remove this and everything blows up. I have no idea why. | ||
|
||
await act(async () => { | ||
await waitFor(() => | ||
expect(mockedAxios.get).toHaveBeenCalledWith("/api/example/get-all") | ||
) | ||
}) | ||
await waitFor(() => | ||
expect(mockedAxios.get).toHaveBeenCalledWith("/api/example/get-all") | ||
) | ||
|
||
const removeBtn = (await findAllByRole("button", { | ||
name: /Remove/i, | ||
}))[0] | ||
|
||
await act(async () => { | ||
await userEvent.click(removeBtn) | ||
}) | ||
await userEvent.click(removeBtn) | ||
|
||
await waitFor(() => | ||
expect(mockedAxios.post).toHaveBeenCalledWith("/api/example", { | ||
|