jasmine 和 jquery-ui -effect() 方法不存在
这很简单。我的 JS 只是调用:
$("#search_box").focus().effect("highlight",{},3000);
describe('initialization', function(){
beforeEach(function(){
var search_box = $("#search_box");
});
it('should initially focus on the search box', function(){
spyOn(search_box, 'focus');
wizard._initialize();
expect(search_box.focus).toHaveBeenCalled();
});
it('should initially highlight the search box', function(){
spyOn(search_box, 'effect');
wizard._initialize();
expect(search_box.effect).toHaveBeenCalledWith("highlight", {}, 3000);
});
});
focus() 有效,但effect 无效。它说effect()方法不存在,就好像我没有加载jquery-ui库一样。
我已将 jquery-ui 添加到我的 jasmine.yml 文件中,并已验证它是否由运行程序加载。
有什么建议吗?
This is pretty simple. My JS is just calling:
$("#search_box").focus().effect("highlight",{},3000);
describe('initialization', function(){
beforeEach(function(){
var search_box = $("#search_box");
});
it('should initially focus on the search box', function(){
spyOn(search_box, 'focus');
wizard._initialize();
expect(search_box.focus).toHaveBeenCalled();
});
it('should initially highlight the search box', function(){
spyOn(search_box, 'effect');
wizard._initialize();
expect(search_box.effect).toHaveBeenCalledWith("highlight", {}, 3000);
});
});
focus() works, but effect does not. It says that the effect() method does not exist, as if I hadn't loaded the jquery-ui library.
I have added jquery-ui to my jasmine.yml file, and have verified that it is loaded by the runner.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有类似的问题。我通过从应用程序的 jasmine.yml 文件中删除这一行来使事情正常工作:
我已明确更改内容以明确包含每个 js 文件。我想人们应该小心使用通配符条目。
希望有帮助,
--何塞
I had a similar problem. I got things working by removing this line from my application's jasmine.yml file:
I've explicitly changed things to include each js file explicitly. I guess one should be careful with the wildcard entry.
Hope it helps,
-- José
如果将来有人需要这个答案:
您不能像这样监视效果方法:
您应该像这样监视效果方法:
In case someone will need this answer in the future:
You cannot spy on effect method like this:
You should spy on effect method like this:
我认为您需要将 search_box 的声明移到 beforeEach 函数之外。
更改:
至:
如果您使用了“use strict”;调试器可能已经指出了这一点。这就是说,使用 JQuery 与 jasmine 间谍也存在问题,我现在没有时间详细说明。
I think you need to move the declaration of search_box outside of the beforeEach function.
Change:
To:
If you had used "use strict"; the debugger might have pointed this out. This said, there are also problems using JQuery with jasmine spys I don't have time to elaborate on now.