Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: format error messages with getErrorMsg()
  • Loading branch information
phra authored Jan 8, 2018
commit bd44ca5eba27d91d0bbe483f42823ceb4cef740b
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