I have a following code:
angular
.module('testApp')
.factory('testDataService', function ($http) {
function testDataService(){
var self = this;
self.test = function(){
//do something
}
self.test1 = function(){
// do something
}
}
return new testDataService();
When I try to write a test case like
beforeEach(function(){
new testDataService();
});
It gives some error like:
> TypeError: '[object Object]' is not a constructor (evaluating 'new testDataService()')
在testDataService中有很多函數,比如「test」,「test1」等。我無法測試剩餘的函數,因爲外層函數的範圍無法訪問。我無法獲得實例,因爲「var self = this」 請幫忙。如何在茉莉花中測試以下功能?
你究竟想要測試什麼?你是否試圖測試你的應用程序可以創建你的工廠?你想測試你的應用程序編譯嗎?等等。這個問題需要更具體。 – mikeswright49
這裏沒有足夠的細節來幫助你。以下是測試角度服務的示例。 https://github.com/angular/angular-seed/blob/master/app/components/version/version_test.js – timsmiths
請閱讀編輯。謝謝。 – Ashwini