0
在這段代碼:Jasmine-對象屬性TOBE()錯誤
var disable = { inputLabelBox : false, nodeIpInput: false, checkBox: false};
var checkDeviceNameExists = function(devices, form) {
return devices.some(function(element) {
nameExists = deviceNameMap(form, element);
if (nameExists) {
form.address.$setViewValue(nameExists);
form.address.$render();
if (!disable.checkBox || !disable.nodeIpInput) {
disable.checkBox = true;
disable.nodeIpInput = true;
checkBox.checked = false;
}
console.log(disable.checkBox);
return true;
} else {
return false;
}
});
}
一切順利,因爲它應該,但我不能讓expect(disable.checkBox).toBe(true);
工作。相反,我得到Expected false to be true
。我已驗證console.log(disable.checkBox);
是否屬實。有什麼建議麼?
beforeEach(function() {
form = {};
form.label = {};
form.address = jasmine.createSpyObj("address", ["$setValidity", "$setViewValue", "$render"]);
form.$setValidity = jasmine.createSpy("$setValidity");
disable = { inputLabelBox : false, nodeIpInput: false, checkBox: false};
});
it("It should populate ip address because Vip label pre-exists", function() {
form.label.$viewValue = "myvip";
FormDeviceExistSvc.checkDeviceExists(form, "checkForVips");
expect(VipSvc.getVips).toHaveBeenCalled();
expect(form.address.$setViewValue).toHaveBeenCalledWith("10.11.11.1");
expect(disable.checkBox).toBe(true);
});
您是否曾嘗試在您的「beforeEach」回調中添加'console.log()'? – Pointy 2014-11-22 21:18:09