定义未定义

时间:2014-12-29 19:52:59

标签: jasmine karma-runner jasmine-jquery

我真的很想让jasmine-jquery和茉莉花一起工作。它不仅可以轻松操控DOM,还可以为我提供大量有用的匹配器。

然而,当我尝试启动我的规范运行时,它给了我这个错误:

 ReferenceError: Can't find variable: define
  at /.../app/vendor/assets/bower_components/jquery/src/jquery.js:37

知道这意味着什么吗?我正在使用Karma来运行我的规格。这是我的unit.js配置:

module.exports = function(config) {
  config.set({
    basePath: '..',

    // frameworks to use
    frameworks: ['jasmine'],
    urlRoot: '/_karma_/',

    // list of files / patterns to load in the browser
    files: [
        'vendor/assets/bower_components/angular/angular.js',
        'vendor/assets/bower_components/angular-mocks/angular-mocks.js',
        'vendor/assets/bower_components/angular-resource/angular-resource.js',
        'vendor/assets/bower_components/angular-cookies/angular-cookies.js',
        'vendor/assets/bower_components/angular-sanitize/angular-sanitize.js',
        'vendor/assets/bower_components/angular-route/angular-route.js',
        'vendor/assets/bower_components/jquery/src/jquery.js', // added this first
        'vendor/assets/jasmine-jquery.js',                     // and then this...
        'vendor/assets/bower_components/jasmine-jquery/lib/jasmine-jquery.js',
        'app/assets/javascripts/application.js.coffee',
        'app/assets/javascripts/**/**',
        'spec/javascripts/**/*'
    ],

    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['dots'],


    // 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,

        autoWatch: true,

    plugins : [
        'jasmine-given',
        'requirejs',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-opera-launcher',
        'karma-jasmine',
        'karma-ng-scenario',
        'karma-phantomjs-launcher',
        'karma-coffee-preprocessor'
    ],

    browsers: ['PhantomJS','Chrome','Firefox','Opera'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false,

    // Preprocessors
    preprocessors: {
        '/**/*.coffee':'coffee',
        '**/*.slim': ['slim', 'ng-html2js']
    }
    /*
    ngHtml2JsPreprocessor: {
      stripPrefix: 'app/assets/templates/',
      stripSufix: '.slim'
    }
    */
  });

我已经完成了,per the instructions是下载jquery,下载jasmine-jquery然后在Karma的spec文件中要求它们:

files: [
        'vendor/assets/bower_components/jquery/src/jquery.js', // added this first
        'vendor/assets/jasmine-jquery.js',                     // and then this...
        ]

但是jquery一直在告诉我undefined未定义错误。

我没有得到关于路径错误的业力警告。

那么如何让jasmine-jquery工作?

可能要求js与其工作有关吗?

1 个答案:

答案 0 :(得分:0)

the response to this question中所述,您需要确保npm下载jasmine-query。 您需要在karma.conf.js中更改以下内容:

frameworks: ['jasmine-jquery', 'jasmine']