I am testing a feature that uses an scroll event listener. I am using the event listener inside a JS hook.
Basically this.
mounted() {
this.el.addEventListener('scroll', () => {
...
this.pushEvent("scroll_changed", ...)
})
}
I am using Wallaby to test this feature, and I have set up Wallaby to scroll to a certain location during the test. And using take_screenshot()
I have confirmed the page indeed gets scrolled to the right location.
feature "", %{session, session} do
user = ...
session
|> log_in_user(user)
|> visit(~p"/read/#{story.id}")
|> scroll_into_view(@resume_location)
end
def scroll_into_view(session, selector) do
execute_script(
session,
"""
document.querySelector(arguments[0]).scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center'
})
""",
[selector]
)
end
I expect to handle the “scroll_changed” event during testing. Outside of testing I always receive the event. During testing I don’t receive the event.
This IO.inspect()
never gets printed.
def handle_event("scroll_changed",_, socket) do
IO.inspect("received!")
end
I also tried using touch_scroll
instead of execute_script
.
Any idea what could explain this behaviour?