How to trigger a scroll event in an acceptance test

I need to trigger a window scroll event to check for infinite scrolling, I tried to use it triggerEvent, but it seems like I'm missing something, and that doesn't work. I am using Ember 2.0, and the list is displayed inside the component, if that matters. The test does not work with the last 2 statements, the scroll position does not change after the event is triggered

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 raised a scroll event in their tests?

+4
source share
2 answers

Finally, I was able to make it work! Instead of a window #ember-testing-container.

Below is the code that 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-infinityyou also need to scroll the body to the start of the test:

Ember.$('body').scrollTop(2000);
+1

.

triggerEvent('.skip-button', 'scroll', [{isInTestEnvironment:true}] ).then...

.skip-button - ember, .

ember, ... isInTestEnvironment: true, ember, .

, , .

0

Source: https://habr.com/ru/post/1606485/


All Articles