【问题标题】:Jasmine pass in broswer, fail in grunt-contrib-jasmineJasmine 在 broswer 中通过,在 grunt-contrib-jasmine 中失败
【发布时间】:2013-10-20 00:32:38
【问题描述】:

我为我的插件创建了一些茉莉花测试。

它们都通过浏览器(chrome)但是由于某种原因,当我在终端中使用“grunt-contrib-jasmine”任务时,它们中的大多数都失败了。

这里是一个例子:

it("scroll to the correct floor", function() {

  // return and instance of my plugin (ascensor)
  var ascensor = getInstanceOfAscensor({});
  var floorArray;

  // Triggered when 'next' is triggered
  ascensor.on("scrollStart", function(event, floor) {
    // floor look like {from:0, to:1}
    floorArray = floor;
  });

  // trigger an 'next' event which
  // trigger a 'scrollStart' 
  // event inside the plugin
  ascensor.trigger("next");

  // Spec
  expect(floorArray.from).toBe(0);
  expect(floorArray.to).toBe(1);
});


Terminal Output:
TypeError: 'undefined' is not an object (evaluating 'floorArray.from')

完整的测试: https://github.com/kirkas/Ascensor.js/blob/master/test/spec/optionsSpec.js

【问题讨论】:

  • 显然scrollStart 事件没有被触发。您可以只发布应该从next 触发器触发它的相关代码吗?仅供参考,我在 github 上打开了一个我在随机查看您的插件时遇到的问题。
  • 感谢您的注意,但问题是在浏览器中测试通过(触发事件),但在 phantomJS 中没有,我不知道为什么。

标签: javascript node.js jasmine phantomjs gruntjs


【解决方案1】:

我发现了问题,我使用的是 jasmine-jquery 中的 loadFixtures 函数,它指的是相对路径 ("spec/javascripts/fixtures")。

解决方案是将此行放在我的测试顶部,它指的是夹具文件夹。

jasmine.getFixtures().fixturesPath = 'path/to/your/fixture';

【讨论】:

    猜你喜欢
    • 2016-05-30
    • 2013-02-06
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多