为什么我使用Jasmine的Javascript测试失败
我正在使用Jasmine jQuery对我的Javascript进行单元测试,但在让这个测试正常工作时遇到了麻烦。我需要确认,当用户滚动页面足够远时,其中一个面板会变粘。这发生在为什么我使用Jasmine的Javascript测试失败,javascript,testing,jasmine,Javascript,Testing,Jasmine,我正在使用Jasmine jQuery对我的Javascript进行单元测试,但在让这个测试正常工作时遇到了麻烦。我需要确认,当用户滚动页面足够远时,其中一个面板会变粘。这发生在Lozenges.makeFixed()方法中,因此我需要确认在窗口scroll上调用此方法。我的考试失败得很惨,不知道我做错了什么。src代码为: mycompany.singleJob=(function($,undefined) { // some code goes here Lozenges obje
Lozenges.makeFixed()
方法中,因此我需要确认在窗口scroll
上调用此方法。我的考试失败得很惨,不知道我做错了什么。src代码为:
mycompany.singleJob=(function($,undefined) {
// some code goes here Lozenges object etc.
function init() {
// more code here
$(window).on("scroll.singleJob",function(e)
{
// at this point if its mobile device simply exit
if(mycompany.framework.isMobile()) return;
// we also need to make first panel sticky
// check if nav is getting out of visible area. it means it should be sticky
if(!LozengesPanel.fixed && $(window).scrollTop()>104)
{
LozengesPanel.makeFixed();
}
else if(LozengesPanel.fixed && $(window).scrollTop()<104)
{
LozengesPanel.makeStatic();
}
});
// more code here
}
// more code here
return {
init:init
};
}(jQuery));
我认为,$(window).scrollTop(500)
应该触发scroll,那么为什么expect
行失败呢
describe("SingleJob page", function() {
beforeEach(function() {
mycompany.singleJob.init();
});
it("panel sticks to top when page scrolled down", function() {
spyOn(mycompany.singleJob.LozengesPanel, "makeFixed");
$(window).scrollTop(500);
expect(mycompany.singleJob.LozengesPanel.makeFixed).toHaveBeenCalled();
});
});