使用Jasmine测试RequireJS
Testing RequireJS with Jasmine
我对Javascript非常陌生,我正在尝试为我加入的一个项目编写测试。我在程序中有这样的文件:
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();
});
});
但是当我运行它时,我得到一个引用错误,茉莉找不到变量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();
});
});
我不太了解Jasmine,但是你不能在require()
呼叫中进行describe()
测试吗?
require(["beatView"], function (beatView) {
describe(...);
});
相关文章:
- 模糊事件的Javascript测试
- 我的单元测试选项是什么
- angularjs、因果报应和requirejs测试用例错误
- 如何通过 phantomjs 可靠地执行利用 requirejs 的 Jasmine 测试
- 因果报应;t转换为requirejs后运行测试
- 如何在单元测试之间重置 requireJS 模块
- 单元测试有状态 RequireJS 模块的模式
- Webpack karma jasmine-requirejs在尝试运行测试时出错
- 如何使用squire模拟内联requirejs依赖关系以进行单元测试
- 为什么在使用 RequireJS 运行摩卡测试时看到“定义未定义”
- 在测试Backbone+RequireJS应用程序时,最好提前加载整个应用程序
- 使用Mocha和requirejs进行测试
- 使用Karma和RequireJS测试CommonJS语法中的文件
- RequireJS——从优化的构建中省略测试代码
- 在RequireJS和QUnit基础中进行单元测试
- 使用Jasmine测试RequireJS
- RequireJS模块shim不工作时,通过茉莉测试
- 主干集成测试:Zombie.js和RequireJS,如何
- RequireJS和Headless测试驱动开发
- 如何在单元测试时模拟特定的 RequireJs 依赖项