Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger scroll event in acceptance test

I need to trigger window scroll event to test infinite scrolling, I've tried to use triggerEvent, but it seems that I missing something and it doesn't work. I'm using Ember 2.0 and list is rendered inside the component if it matters. Test fails on last 2 assertions, scroll position doesn't change after triggering event

test 'loads more items when scrolling', (assert) ->
  visit '/locations/1'   
  andThen ->
    assert.equal(find('.items-list li').length, 30)

    find(window).scrollTop(10000)
    triggerEvent(window, 'scroll')

    andThen ->
      assert.ok(find(window).scrollTop() > 0, 'window should scroll')
      assert.ok(find('.items-list li').length > 30, 'should load more items after reaching threshold')

Has anyone successfully triggered scroll event in their tests?

like image 507
ExD Avatar asked Nov 10 '22 05:11

ExD


1 Answers

Finally I could make it work! Used #ember-testing-container instead window.

The code below was what worked for me:

andThen(() => {
  Ember.$('#ember-testing-container').scrollTop(10000);
});

triggerEvent(Ember.$('#ember-testing-container'), 'scroll');

andThen(() => {
  assert.ok(Ember.$('#ember-testing-container').scrollTop() > 0, 'window should scroll')
});

With ember-infinity you also need to scroll down the body before starting the test:

Ember.$('body').scrollTop(2000);
like image 101
William Weckl Avatar answered Jan 04 '23 02:01

William Weckl