[英]Testing RequireJS with Jasmine
我是Java语言的新手,我正为参与的项目编写测试。 我在程序中有如下文件:
define([
'jquery',
'underscore',
'backbone',
'backbone/models/beat',
'colors',
'app/dispatch',
'app/log'
], function($, _, Backbone, BeatModel, COLORS, dispatch, log){
return Backbone.View.extend({
getOpacityNumber : function(bool) {
//code
},
unroll: function(){
//code
}
});
});
我无法弄清楚如何在测试中访问这些功能。 我尝试实例化一个对象(尽管我可能做错了),然后从那里调用函数,如下所示:
describe("beatView.js", function() {
beforeEach( function() {
var b = new beatView();
});
spyOn(console, "log");
it("test the console log", function() {
b.unroll();
expect(console.log).toHaveBeenCalled();
});
});
但是当我运行它时,我收到一个参考错误,Jasmine无法找到变量b。 有什么我想念的吗? 向我指出正确方向的任何帮助将不胜感激。
请尝试以下操作:
describe("beatView.js", function() {
var b = null;
beforeEach( function() {
b = new beatView();
});
spyOn(console, "log");
it("test the console log", function() {
b.unroll();
expect(console.log).toHaveBeenCalled();
});
});
我不太了解茉莉花,但您不能只在require()
调用中describe()
测试吗?
require(["beatView"], function (beatView) {
describe(...);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.