2014-06-10 27 views
0

我已經看了幾天,現在我明顯失去了一些東西。我已經通過Google進行了搜索,並嘗試從其他許多人中繼續使用egghead.io中的示例。我已經成功將業力安裝到WebStorm 8.0.3中,並且我可以運行測試測試,例如expect(true).toBe(true)expect(false).toBe(true),並獲得預期的結果。但是,當我嘗試測試helloWorld()函數時,我收到一個helloWorld未定義的引用錯誤。Karma如何知道在WebStorm中尋找功能的位置?

如何告訴我的測試腳本我的腳本被測試的位置是?

我的文件結構:

-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' 
} 

感謝

回答

0

您需要加載您helloworld.js因果報應配置:

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

你目前只加載試驗,使的helloWorld()是不明噶

+0

該訣竅。我以爲我曾嘗試過,但我不能。謝謝 :) – lappy