Karma如何知道在WebStorm中寻找功能的位置?

时间:2014-06-10 22:12:55

标签: javascript webstorm karma-runner karma-jasmine

我一直在研究这几天,我显然遗漏了一些东西。我在Google上搜索过,并尝试从egghead.io中跟踪其他许多例子。我已成功将业力安装到WebStorm 8.0.3中,我可以运行expect(true).toBe(true)expect(false).toBe(true)等测试测试,并获得预期的结果。但是,当我尝试测试helloWorld()函数时,我收到一个未定义helloWorld的引用错误。

如何告诉我的测试脚本我要测试的脚本在哪里?

我的文件结构:

    -scripts
    --helloWorld.js
    -test
    --spec.js
    karma.conf.js

karma.conf.js(由WebStorm生成的开箱即用):

// Karma configuration
// Generated on Tue Jun 10 2014 16:47:49 GMT+0100 (GMT 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: [
  '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: false,


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


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

spec.js:

describe('heelo world', function(){
    it('should say hello', function(){
        expect(helloWorld()).toBe('hello world')
    })
})

helloWorld.js:

var helloWorld = function(){
    return 'hello world'
}

由于

1 个答案:

答案 0 :(得分:0)

您需要在karma配置中加载helloworld.js:

files: [
            'test/spec.js',
            'scripts/helloWorld.js'
        ],

你目前只加载测试,所以helloWorld()对业力来说是未知的