茉莉花测试要求未定义

时间:2015-09-05 15:37:45

标签: javascript jasmine karma-jasmine

我有以下测试

require ('./src/gameService.js');
describe('gameService', function(){
    describe('getState', function(){
        it('should return the state of the box', function(){
            gameService.gameState[1][2]=true;
            expct(gameService.getState(1,2)).toBe(true);
        })
    })
})

gameService.js

中的以下代码
var gameState = []

...

this.getState = function(row, column){
    return gameState[row][column];
}

当我运行业力时(使用茉莉花)

Chrome 45.0.2454 (Windows 7 0.0.0) ERROR
  Uncaught ReferenceError: require is not defined
  at C:/devl/JS/FUSE/test/gameServiceSpec.js:1


IE 11.0.0 (Windows 7 0.0.0) ERROR
  'require' is undefined
  at C:/devl/JS/FUSE/test/gameServiceSpec.js:1


Firefox 38.0.0 (Windows 7 0.0.0) ERROR
  ReferenceError: require is not defined
  at C:/devl/JS/FUSE/test/gameServiceSpec.js:1

根据我的理解,茉莉应该接受要求声明。

我的karma.conf.js

// Karma configuration
// Generated on Sat Sep 05 2015 10:46:37 GMT-0400 (Eastern Daylight Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      {pattern: 'bower_components/angular/angular.js'},
      {pattern: 'src/**/*.js'},
      {pattern: 'test/**/*Spec.js'}
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome', 'Firefox', 'IE'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  })
}

0 个答案:

没有答案