This is my first question to Stack Overflow and Jasmine is fairly new to me, so I hope I'm doing ok here.
I have a Jasmine test where I try to set the scroll position of my page to a certain value. The actual code is pretty complex, but I managed to make a more simple example of the failing test:
it("should set scrollTop to equal 100", function () {
setFixtures("<div id='page' style='height: 1000px;'>Page content</div>");
spyOn($.fn, "scrollTop");
$("#page").scrollTop(100);
expect($.fn.scrollTop).toHaveBeenCalledWith(100); // this test passes
expect($("#page").scrollTop()).toEqual(100);
});
The result: Expected 0 to equal 100.
I set the scrollTop to 100 and expect it to be just that on the next line. How does this test fail?
If it matters, I'm using Jasmine 1.3.1 with requirejs and jasmine-jquery as an extension.
scrollTop
and end. Please consider to usecallThrough
orcallFake
to have knowledge about whats happening. One other thing to do … You can putdebugger
statemanet before firstexpect
and run test in webbrowser (please also open console, so browser can catchdebugger
) – Tajo