Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test to verify no network request on prefetched link click #1257

Conversation

davidalejandroaguilar
Copy link
Contributor

Description

The test aimed to verify that no network request occurs when clicking a link that had already been prefetched by hovering. However, instead of performing a click, the test erroneously attempted to hover over the link again, which had already been hovered over. Therefore, it failed to test the intended behavior.

This PR makes sure that the test is correctly set up to prevent any regression in this functionality.

The test was supposed to assert that a network
request was not made when clicking on a link that
had been prefetched by hovering over it. However,
the test was not actually making the click, just
trying to hover over an already hovered link, so
this wasn't really testing what it was supposed to.
src/tests/functional/link_prefetch_observer_tests.js Outdated Show resolved Hide resolved
let requestMade = false
page.on("request", async (request) => (requestMade = true))
await clickSelector({ page, selector })
assertRequestNotMade(requestMade)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a callback to the assertRequestMade / assertRequestNotMade helpers so we can move the requestMade and event handler declaration to the helpers, so this looks like:

assertRequestNotMade(async () => {
  await clickSelector({ page, selector })
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just got free right now to tackle this.

Good call, love the resulting abstraction. LMK if this is what you had in mind.

These functions are called to perform the action that should trigger the
network request. This allows us to test different scenarios without
repeating the same code.

It also allows us to pass a callback that will be called with the request
object when the request is made. This is useful for testing the request
object itself.
@afcapel afcapel merged commit 8c706bb into hotwired:main May 20, 2024
1 check passed
@afcapel
Copy link
Collaborator

afcapel commented May 20, 2024

Thanks @davidalejandroaguilar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants