0
我似乎無法圍繞測試AngularJS應用程序的概念進行探討。瞭解AngularJS測試
我使用PHPstorm作爲我的IDE,並且已經成功地通過節點安裝了node.js和karma。
我已經然後創建了一個karma.config文件:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'js/angular.js',
'js/va.angular.js',
'test/**/**/*Spec.js'
],
exclude: [
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'],
captureTimeout: 60000,
singleRun: false
});
};
我還創建了一個測試文件:
// mainSpec.js
describe('controllers', function(){
beforeEach(angular.module('va'));
it('should friggin test something', inject(function() {
var x = 5;
expect(x.toBe(5));
}));
});
然而,正如我嘗試運行我的測試,它失敗,因爲:
TypeError: Object #<Object> has no method 'apply'
TypeError: Object 5 has no method 'toBe'
現在我有2個問題:
- 我在這做錯了什麼?
- 業務從哪裏得到茉莉花的東西?對我來說,它看起來不能得到它。
非常感謝你爲止! 您是否介意簡要說明angular-mocks.js用於什麼以及在哪裏可以找到它的模板? – user2422960
angular-mocks是一組功能,用於模擬角度的不同組件。例如,如果您想測試從您的服務器返回的數據是否正確地填充到對象中,您可以模擬'$ http'服務並使其返回一個虛擬數據,而無需調用實際的Web服務。這可能會幫助您瞭解測試http://www.benlesh.com/2013/05/angularjs-unit-testing-controllers.html – javaCity
再次感謝。我將它包含了,並解決了toBe()的錯誤,但我仍然得到一個適用於() – user2422960