Dusk: Testing an ajax request performed by a Modal onScroll event

Submitted by nezarfadle - 7 years ago

This code shows how to trigger a Modal onScroll event to perform and assert against an ajax request

// Make the first request

$browser->visit('/page')
        ->clickLink('search') // Assuming this will open the Modal
        ->waitFor('.selector')
        ->assertSee('Text 1');

// Assert the next comming text is not there
$browser->assertDontSee('Text 2');

// Trigger the Modal scroll event to perform the second ajax request
// Note: The value  ( 10 ) depends on how you handle the onScroll event

$browser->driver->executeScript('var el = $(".modal-content"); el.scrollTop( el.prop("scrollHeight") + 10 );');

// Wait until the Preloader disappear and make the assertion
$browser->waitUntilMissing('.preloader-wrapper')
        ->assertSee('Text 2');