Merge branch 'enelson/spyregerrors' of https://github.com/elliot-nelson/jasmine into elliot-nelson-enelson/spyregerrors
- Merges #1706 from @elliot-nelson
This commit is contained in:
@@ -6393,7 +6393,8 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
|
|
||||||
getJasmineRequireObj().SpyRegistry = function(j$) {
|
getJasmineRequireObj().SpyRegistry = function(j$) {
|
||||||
|
|
||||||
var getErrorMsg = j$.formatErrorMsg('<spyOn>', 'spyOn(<object>, <methodName>)');
|
var spyOnMsg = j$.formatErrorMsg('<spyOn>', 'spyOn(<object>, <methodName>)');
|
||||||
|
var spyOnPropertyMsg = j$.formatErrorMsg('<spyOnProperty>', 'spyOnProperty(<object>, <propName>, [accessType])');
|
||||||
|
|
||||||
function SpyRegistry(options) {
|
function SpyRegistry(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -6401,11 +6402,12 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
var createSpy = options.createSpy;
|
var createSpy = options.createSpy;
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow) {
|
||||||
this.respy = allow;
|
this.respy = allow;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
|
var getErrorMsg = spyOnMsg;
|
||||||
|
|
||||||
if (j$.util.isUndefined(obj) || obj === null) {
|
if (j$.util.isUndefined(obj) || obj === null) {
|
||||||
throw new Error(getErrorMsg('could not find an object to spy upon for ' + methodName + '()'));
|
throw new Error(getErrorMsg('could not find an object to spy upon for ' + methodName + '()'));
|
||||||
@@ -6459,35 +6461,37 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnProperty = function (obj, propertyName, accessType) {
|
this.spyOnProperty = function (obj, propertyName, accessType) {
|
||||||
|
var getErrorMsg = spyOnPropertyMsg;
|
||||||
|
|
||||||
accessType = accessType || 'get';
|
accessType = accessType || 'get';
|
||||||
|
|
||||||
if (j$.util.isUndefined(obj)) {
|
if (j$.util.isUndefined(obj)) {
|
||||||
throw new Error('spyOn could not find an object to spy upon for ' + propertyName + '');
|
throw new Error(getErrorMsg('spyOn could not find an object to spy upon for ' + propertyName + ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j$.util.isUndefined(propertyName)) {
|
if (j$.util.isUndefined(propertyName)) {
|
||||||
throw new Error('No property name supplied');
|
throw new Error(getErrorMsg('No property name supplied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
var descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
||||||
|
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
throw new Error(propertyName + ' property does not exist');
|
throw new Error(getErrorMsg(propertyName + ' property does not exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!descriptor.configurable) {
|
if (!descriptor.configurable) {
|
||||||
throw new Error(propertyName + ' is not declared configurable');
|
throw new Error(getErrorMsg(propertyName + ' is not declared configurable'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!descriptor[accessType]) {
|
if(!descriptor[accessType]) {
|
||||||
throw new Error('Property ' + propertyName + ' does not have access type ' + accessType);
|
throw new Error(getErrorMsg('Property ' + propertyName + ' does not have access type ' + accessType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j$.isSpy(descriptor[accessType])) {
|
if (j$.isSpy(descriptor[accessType])) {
|
||||||
if (this.respy) {
|
if (this.respy) {
|
||||||
return descriptor[accessType];
|
return descriptor[accessType];
|
||||||
} else {
|
} else {
|
||||||
throw new Error(propertyName + '#' + accessType + ' has already been spied upon');
|
throw new Error(getErrorMsg(propertyName + ' has already been spied upon'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
getJasmineRequireObj().SpyRegistry = function(j$) {
|
getJasmineRequireObj().SpyRegistry = function(j$) {
|
||||||
|
|
||||||
var getErrorMsg = j$.formatErrorMsg('<spyOn>', 'spyOn(<object>, <methodName>)');
|
var spyOnMsg = j$.formatErrorMsg('<spyOn>', 'spyOn(<object>, <methodName>)');
|
||||||
|
var spyOnPropertyMsg = j$.formatErrorMsg('<spyOnProperty>', 'spyOnProperty(<object>, <propName>, [accessType])');
|
||||||
|
|
||||||
function SpyRegistry(options) {
|
function SpyRegistry(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -8,11 +9,12 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
var createSpy = options.createSpy;
|
var createSpy = options.createSpy;
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow) {
|
||||||
this.respy = allow;
|
this.respy = allow;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
|
var getErrorMsg = spyOnMsg;
|
||||||
|
|
||||||
if (j$.util.isUndefined(obj) || obj === null) {
|
if (j$.util.isUndefined(obj) || obj === null) {
|
||||||
throw new Error(getErrorMsg('could not find an object to spy upon for ' + methodName + '()'));
|
throw new Error(getErrorMsg('could not find an object to spy upon for ' + methodName + '()'));
|
||||||
@@ -66,35 +68,37 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnProperty = function (obj, propertyName, accessType) {
|
this.spyOnProperty = function (obj, propertyName, accessType) {
|
||||||
|
var getErrorMsg = spyOnPropertyMsg;
|
||||||
|
|
||||||
accessType = accessType || 'get';
|
accessType = accessType || 'get';
|
||||||
|
|
||||||
if (j$.util.isUndefined(obj)) {
|
if (j$.util.isUndefined(obj)) {
|
||||||
throw new Error('spyOn could not find an object to spy upon for ' + propertyName + '');
|
throw new Error(getErrorMsg('spyOn could not find an object to spy upon for ' + propertyName + ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j$.util.isUndefined(propertyName)) {
|
if (j$.util.isUndefined(propertyName)) {
|
||||||
throw new Error('No property name supplied');
|
throw new Error(getErrorMsg('No property name supplied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
var descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
||||||
|
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
throw new Error(propertyName + ' property does not exist');
|
throw new Error(getErrorMsg(propertyName + ' property does not exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!descriptor.configurable) {
|
if (!descriptor.configurable) {
|
||||||
throw new Error(propertyName + ' is not declared configurable');
|
throw new Error(getErrorMsg(propertyName + ' is not declared configurable'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!descriptor[accessType]) {
|
if(!descriptor[accessType]) {
|
||||||
throw new Error('Property ' + propertyName + ' does not have access type ' + accessType);
|
throw new Error(getErrorMsg('Property ' + propertyName + ' does not have access type ' + accessType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j$.isSpy(descriptor[accessType])) {
|
if (j$.isSpy(descriptor[accessType])) {
|
||||||
if (this.respy) {
|
if (this.respy) {
|
||||||
return descriptor[accessType];
|
return descriptor[accessType];
|
||||||
} else {
|
} else {
|
||||||
throw new Error(propertyName + '#' + accessType + ' has already been spied upon');
|
throw new Error(getErrorMsg(propertyName + ' has already been spied upon'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user