开发者

Jasmine, JQuery UI addClass Test Problem

开发者 https://www.devze.com 2023-03-13 00:37 出处:网络
I\'m tr开发者_运维知识库ying to test the simplest case of addClass with a duration (using jQuery UI and Jasmine).

I'm tr开发者_运维知识库ying to test the simplest case of addClass with a duration (using jQuery UI and Jasmine).

Here's the test that's failing:

it("should use jquery ui", function() {
  runs(function() {
    expect(el.hasClass("fdsa")).toBeFalsy();
    el.addClass("fdsa", 1000);
    expect(el.hasClass("fdsa")).toBeFalsy();// this should not be failing, but it is
  });

  waits(1000);

  runs(function() {
    expect(el.hasClass("fdsa")).toBeTruthy();
  });
});

My expectation is that it wouldn't have the class until after 1000 milliseconds. When I test this from the browser console, it behaves this way.

This is the sanity check that I used (tested in the Jasmine browser window).

el = $($("div")[0]);
el.addClass("qwer", 1000);
console.log(el.hasClass("qwer")); // output is "false"
setTimeout( function(){
  console.log(el.hasClass("qwer")); // output is "true"
}, 1001);

And this works always. WTF?


I took the time to setup a fiddle for it: http://jsfiddle.net/ahus1/pZGdP/

I 'invented' what was necessary to get it working, like the beforeEach. I don't know the versions you used, but in this sample I used the latest ones available.

I noticed that it was only starting to work when I really added a proper class to the stylesheet. When there is no .fdsa class in the CSS, there's no transition, and the test will fail.

Maybe the fiddle will solve it for you. Please have a look.

Best regards, Alexander.

0

精彩评论

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