我为我的插件创建了一些茉莉花测试。
它们都在浏览器(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