Abort spying when the target cannot be spied on

This commit is contained in:
Stephan Bijzitter
2015-10-21 12:44:52 +02:00
parent 48f42eaa7d
commit a81466d9e7
2 changed files with 31 additions and 0 deletions

View File

@@ -22,6 +22,11 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
throw new Error(methodName + ' has already been spied upon');
}
var descriptor = Object.getOwnPropertyDescriptor(obj, methodName);
if (!(descriptor.writable || descriptor.set)) {
throw new Error(methodName + ' is not declared writable or has no setter');
}
var spy = j$.createSpy(methodName, obj[methodName]);
currentSpies().push({