0
我正在使用Jasmine,Karma和PhantomJS來自動化我的測試,但是我遇到一個問題:Phantom似乎沒有正確解析我的JS。例如,我用這個模擬:在Karma測試中缺少函數
var App = function() {
return {
pageController : {
currentPage : {
on : function() {},
toJSON : function() {},
get : function() {
return dark;
}
}
},
mainLayout : {
header : {
show : function() {},
$el : {}
}
}
};
};
console.log("in test", App());
...這登出如下:
PhantomJS 1.9 (Mac) LOG: [ 'in test',
{ pageController: {},
mainLayout: { header: [Object] } } ]
app.pageController這裏已經清空,這會導致我的測試失敗。爲什麼會發生這種情況&我該如何修復它?
這個問題似乎直接與函數定義有關。例如:
console.log("this is a function:", function() { return 'wat'; });
產生
PhantomJS 1.9 (Mac) LOG: [ 'this is a function:', null ]
該錯誤也出現在瀏覽器。它也粉碎了創建的茉莉間諜,所以我猜這是與噶瑪有關?