首先,我看到了这个post,它给了我更多的错误(见下) .

我收到这些错误:

ReferenceError:找不到变量:require at test / spec / test.js:1 TypeError:'undefined'不是bower_components / underscore / underscore.js的对象(评估'text.replace'):1180 src / js /script.js:12 src / js / script.js:56 src / js / script.js:194 ReferenceError:找不到变量:require at test / spec / test.js:1

当试图使用Grunt时 .

这是我的Grunt文件:

module.exports = function (grunt) {
jasmine: {
            src: 'src/js/*.js',
            options: {
                specs: 'test/spec/*.js',
                helpers: 'test/spec/*.js',
                vendor: [
                    'bower_components/jquery/jquery.js',
                    'bower_components/underscore/underscore.js',
                    'bower_components/backbone/backbone.js'
                ]
            }
        }
    });

grunt.registerTask('default', ['clean', 'jasmine']);

这是我的测试文件:

var chai = require('chai')
var Backbone = require('backbone');
var _ = require('underscore');
describe('Underscore & Backbone to be defined', function() {
    it('should be loaded', function() {
        chai.should.exist(_);
        chai.should.exist(Backbone);
    })
})

顺便说一下,我没有使用requirejs .


添加grunt-template-jasmine-requirejs时, enter code here 我收到以下错误:

错误:尚未为上下文加载模块名称“jquery”:_ . 使用require([])>> http://requirejs.org/docs/errors.html#notloaded at >> .grunt / grunt-contrib-jasmine / require.js:8 aa >> .grunt / grunt-contrib- jasmine / require.js:12 v >> .grunt / grunt-contrib-jasmine / require.js:26 h >> .grunt / grunt-contrib-jasmine / require.js:31 >> test / spec / test.js :1 >> TypeError:'undefined'不是一个对象(评估'text.replace')>> bower_components / underscore / underscore.js:1180 >> src / js / script.js:12 >> src / js / script.js:56 >> src / js / script.js:194 >>错误:未加载:模块名称“jquery”尚未加载上下文:_ . 使用require([])>> http://requirejs.org/docs/errors.html#notloaded at >> _SpecRunner.html:46 >> .grunt / grunt-contrib-jasmine / require.js:12 v >> .grunt / grunt-contrib-jasmine / require.js:26 h >> .grunt / grunt-contrib-jasmine / require.js:31 >> test / spec / test.js:1