我創造了這個小片的代碼被執行最好的方式來測試,如果內部對象的方法
function myFunction() {
var myObject = {
objProperty: "string",
objMethod: function() {
return myObject.objProperty;
}
};
return myObject.objMethod();
};
現在我試圖讓單元測試,如果代碼工作將檢查作爲它應該:
describe("checking syntax and function integrity", function(){
// called before each spec is ran
before(function(){
});
it ("should return 'string' when myFunction is called", function(){
Test.assertEquals(myFunction(), 'string', 'myFunction did not return "string"');
});
it ("should check if myObject.objMethod was called", function(){
});
});
我的問題:是否可以檢查myObject.objMethod是否被調用?我正在使用由CodeWars提供的測試框架。
Here is a link to their test framework。
'Test.callCount(methodName)→Integer' 返回調用Test方法的次數。創建需要測試測試方法使用情況的kata時非常有用。在使用Test助手方法時,在kata解決方案中不允許使用。您可以簡單地測試是否有任何禁止呼叫。 – n00dl3
您能否提供一個關於您認爲應該如何寫測試的答案? – mdarmanin
嗯實際上它似乎只涉及測試方法... – n00dl3