为什么我的jquery选择器返回undefined?

时间:2016-02-17 05:37:48

标签: jquery meteor jasmine jasmine-jquery

我使用jasmine为我的meteor应用程序进行单元测试,我的一个测试是测试DOM元素是否已被隐藏。但是当使用jQuery选择Dom时,它会返回undefined,从而导致我的测试失败。

茉莉花测试:

it("should filter all cards by single tag", function(){
      event = jasmine.createSpyObj("event",["target","preventDefault"]);
      event = {
        target: {
          thoughts : {value: "testThought"},
          tags: {value: "testTag"},
          author: {value: "testAuthor"},
          goodCategoryRadio: {checked: true},
          badCategoryRadio: {checked: false}
        },
        preventDefault: function(){}
      };
      spyOn(Session, "get").and.returnValue("testRoom");
      spyOn(Session, "set");
      var baseTime = new Date();
      jasmine.clock().mockDate(baseTime);

      Template.card.fireEvent("submit #card");
      event = {
        target: {
          thoughts : {value: "testThought"},
          tags: {value: "different tag"},
          author: {value: "testAuthor"},
          goodCategoryRadio: {checked: true},
          badCategoryRadio: {checked: false}
        },
        preventDefault: function(){}
      };
      baseTime = new Date();
      jasmine.clock().mockDate(baseTime);

      Template.card.fireEvent("submit #card");
      tagEvent = jasmine.createSpyObj("event",["toElement.innerHTML"]);
      tagEvent = {
        toElement: { value: "<tag class='tag'>testTag</tag>"}
      };
      Template.room.fireEvent("click tag", {event: tagEvent});
      expect($("div#card").eq(1).is(":visible")).toBeVisible();
      expect($("div#card").eq(0).is(":visible")).toBeHidden();
    });

0 个答案:

没有答案