karma: Bug: window scrolling

I would like to use testacular for testing a window-scroll-related utility.

There seems to a bug wherein I cannot get correct scrolling behaviour. Given this code:

chai.should()

describe("foo", function () {

  it("bar", function () {
    $('body').append('<div id="foo"></div>')
    $('#foo').css('height', 3000)
    dump(window.innerHeight)
    window.innerHeight.should.equal(300)
    window.scrollY.should.equal(0)
    window.scrollTo(window.scrollX, 50)
    window.scrollY.should.equal(50)
  });
});

I get the unexpected error:

info (watcher): Changed file "/Users/jasonkuhrt/projects/components/scroll-over/test.js".
PhantomJS 1.7 DUMP: 300
PhantomJS 1.7 foo bar FAILED
    expected 0 to equal 50
        at /Users/jasonkuhrt/projects/components/scroll-over/node_modules/chai/chai.js:258
        at assertEqual (/Users/jasonkuhrt/projects/components/scroll-over/node_modules/chai/chai.js:662)
        at /Users/jasonkuhrt/projects/components/scroll-over/node_modules/chai/chai.js:2780
        at /Users/jasonkuhrt/projects/components/scroll-over/test.js:15
PhantomJS 1.7: Executed 1 of 1 (1 FAILED) (0.031 secs / NaN secs)

The specific assertion failing is:

    window.scrollY.should.equal(50)

I am able to make this test pass with mocha-phantomjs. Whatโ€™s going on in this testacular context?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Wrapping aroung window.setTimeout did the trick. thx ๐Ÿ‘

Got it working ๐Ÿ˜„

it('becomes "fixed" when scrolling past the break point', function (done) {
    var node = React.findDOMNode(component);
    document.body.style.height = '10000px';
    document.body.appendChild(node.parentNode); //this is the key
    window.scrollTo(0, component.SCROLL_BREAK_POINT + 1);
    window.setTimeout(function () {
        expect(window.getComputedStyle(node).position.toLowerCase()).toEqual('fixed');
        document.body.style.height = '';
        document.body.removeChild(node.parentNode);
        done();
    }, 150)
  });