开发者

jasmine and jquery-ui - effect() method does not exist

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 effe开发者_C百科ct 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?


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é


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');


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜