jasmine 和 jquery-ui -effect() 方法不存在

发布于 2024-10-11 10:34:04 字数 841 浏览 4 评论 0原文

这很简单。我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

素衣风尘叹 2024-10-18 10:34:04

我有类似的问题。我通过从应用程序的 jasmine.yml 文件中删除这一行来使事情正常工作:

- public/javascripts/**/*.js

我已明确更改内容以明确包含每个 js 文件。我想人们应该小心使用通配符条目。

希望有帮助,

--何塞

I had a similar problem. I got things working by removing this line from my application's jasmine.yml file:

- public/javascripts/**/*.js

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é

愿与i 2024-10-18 10:34:04

如果将来有人需要这个答案:

您不能像这样监视效果方法:

spyOn(search_box, 'effect');

您应该像这样监视效果方法:

spyOn($.fn, 'effect');

In case someone will need this answer in the future:

You cannot spy on effect method like this:

spyOn(search_box, 'effect');

You should spy on effect method like this:

spyOn($.fn, 'effect');
贪恋 2024-10-18 10:34:04

我认为您需要将 search_box 的声明移到 beforeEach 函数之外。

更改:

describe('initialization', function(){
    beforeEach(function(){
        var search_box = $("#search_box");
    });
});

至:

describe('initialization', function(){
    var search_box;
    beforeEach(function(){
        search_box = $("#search_box");
    });
});

如果您使用了“use strict”;调试器可能已经指出了这一点。这就是说,使用 JQuery 与 jasmine 间谍也存在问题,我现在没有时间详细说明。

I think you need to move the declaration of search_box outside of the beforeEach function.

Change:

describe('initialization', function(){
    beforeEach(function(){
        var search_box = $("#search_box");
    });
});

To:

describe('initialization', function(){
    var search_box;
    beforeEach(function(){
        search_box = $("#search_box");
    });
});

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文