Skip to content

Commit

Permalink
refactor: format error messages with getErrorMsg()
Browse files Browse the repository at this point in the history
  • Loading branch information
phra authored Jan 8, 2018
1 parent 95f0ab9 commit bd44ca5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/jest-jasmine2/src/jasmine/spy_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ export default function SpyRegistry(options: Object) {
this._spyOnProperty = function(obj, propertyName, accessType = 'get') {
if (!obj) {
throw new Error(
'spyOn could not find an object to spy upon for ' + propertyName + '',
getErrorMsg(
'could not find an object to spy upon for ' + propertyName,
),
);
}

if (!propertyName) {
throw new Error('No property name supplied');
throw new Error(getErrorMsg('No property name supplied'));
}

let descriptor;
Expand All @@ -152,16 +154,18 @@ export default function SpyRegistry(options: Object) {
}

if (!descriptor) {
throw new Error(propertyName + ' property does not exist');
throw new Error(getErrorMsg(propertyName + ' property does not exist'));
}

if (!descriptor.configurable) {
throw new Error(propertyName + ' is not declared configurable');
throw new Error(getErrorMsg(propertyName + ' is not declared configurable'));
}

if (!descriptor[accessType]) {
throw new Error(
'Property ' + propertyName + ' does not have access type ' + accessType,
getErrorMsg(
'Property ' + propertyName + ' does not have access type ' + accessType,
)
);
}

Expand Down

0 comments on commit bd44ca5

Please sign in to comment.