Skip to content

Commit

Permalink
toggleLoading: fix race (#27905)
Browse files Browse the repository at this point in the history
* toggleLoading: fix race

* add a test

* add second test

* lint🤕

* timer should be called
  • Loading branch information
samouri committed Apr 22, 2020
1 parent 701c62c commit 8b35b32
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/unit/test-custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,12 +1992,26 @@ describes.realWin('CustomElement', {amp: true}, (env) => {
expect(toggle).calledOnceWith(true, {startTime: 42});
});

it('should not schedule it to turn on if already laid out when enters viewport', () => {
stubInA4A(false);
const timerDelay = env.sandbox.spy(Services.timerFor(win), 'delay');
const toggle = env.sandbox.spy(element, 'toggleLoading');
element.layoutCount_ = 1;
element.viewportCallback(true);
clock.tick(1000);

expect(timerDelay).to.have.not.been.called;
expect(toggle).to.have.not.been.called;
});

it('should NOT turn on when enters viewport but already laid out', () => {
stubInA4A(false);
const timerDelay = env.sandbox.spy(Services.timerFor(win), 'delay');
const toggle = env.sandbox.spy(element, 'toggleLoading');
element.viewportCallback(true);
element.layoutCount_ = 1;
clock.tick(1000);
expect(timerDelay).to.have.been.called;
expect(toggle).to.have.not.been.called;
});

Expand Down

0 comments on commit 8b35b32

Please sign in to comment.