它在karma-jasmine上工作得很好……但是不能和karma-mocha……y??
module.exports = function(config){
config.set({
basePath : '../app',
preprocessors: {
'**/*.html':'ng-html2js'
},
ngHtml2JsPreprocessor: {
prependPrefix: '/'
},
files : [
'node_modules/jquery/**/*.js',
'lib/angular/angular.js',
'lib/angular/angular-*.js',
'../test/lib/angular-mocks.js',
'../test/lib/sinon-1.15.0.js',
'../test/lib/chai.js',
'js/**/*.js',
'../test/unit/**/*.js',
'**/*.html'
],
autoWatch : true,
frameworks: ['mocha','requirejs','chai'],
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-mocha',
'karma-ng-html2js-preprocessor',
'karma-requirejs',
'karma-chai'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});};
我的示例代码:
'use strict';
describe('calendarHelper', function() {
beforeEach(module('eventsApp'));
it('should return January when given a zero', inject(function(calendarHelper) {
expect(calendarHelper.getMonthName(0)).toBe('January');
}))
});发布于 2016-07-15 22:27:26
我在使用Jasmine时遇到了类似的情况。我想介绍一下我的解决方案。
尝试错误消息中所写的内容。这里有一个网站的链接:http://requirejs.org/docs/errors.html#notloaded
在您的等级库文件中使用以下代码:
//If this code is not in a define call,
//DO NOT use require('foo'), but use the async
//callback version:
require(['foo'], function (foo) {
//foo is now loaded.
});我在Coffeescript中为Jasmine和Sinon写的案例是这样的:
sinon = require(['sinon', 'jasmine-sinon']) (foo)->现在,我可以在单元测试中使用sinon作为对象,也可以遵循sinon以及jasmin-sinon的文档。
https://stackoverflow.com/questions/36118185
复制相似问题