Throw an Error rather than a string when createSpyObj is called incorectly

This commit is contained in:
Steve Gravrock
2025-08-23 08:19:11 -07:00
parent 63774597f0
commit 8d99f27be8
3 changed files with 9 additions and 5 deletions

View File

@@ -9964,7 +9964,9 @@ getJasmineRequireObj().SpyFactory = function(j$) {
} }
if (methods.length === 0 && properties.length === 0) { if (methods.length === 0 && properties.length === 0) {
throw 'createSpyObj requires a non-empty array or object of method names to create spies for'; throw new Error(
'createSpyObj requires a non-empty array or object of method names to create spies for'
);
} }
return obj; return obj;

View File

@@ -153,7 +153,7 @@ describe('Spies', function() {
it('should throw if you do not pass an array or object argument', function() { it('should throw if you do not pass an array or object argument', function() {
expect(function() { expect(function() {
env.createSpyObj('BaseName'); env.createSpyObj('BaseName');
}).toThrow( }).toThrowError(
'createSpyObj requires a non-empty array or object of method names to create spies for' 'createSpyObj requires a non-empty array or object of method names to create spies for'
); );
}); });
@@ -161,7 +161,7 @@ describe('Spies', function() {
it('should throw if you pass an empty array argument', function() { it('should throw if you pass an empty array argument', function() {
expect(function() { expect(function() {
env.createSpyObj('BaseName', []); env.createSpyObj('BaseName', []);
}).toThrow( }).toThrowError(
'createSpyObj requires a non-empty array or object of method names to create spies for' 'createSpyObj requires a non-empty array or object of method names to create spies for'
); );
}); });
@@ -169,7 +169,7 @@ describe('Spies', function() {
it('should throw if you pass an empty object argument', function() { it('should throw if you pass an empty object argument', function() {
expect(function() { expect(function() {
env.createSpyObj('BaseName', {}); env.createSpyObj('BaseName', {});
}).toThrow( }).toThrowError(
'createSpyObj requires a non-empty array or object of method names to create spies for' 'createSpyObj requires a non-empty array or object of method names to create spies for'
); );
}); });

View File

@@ -54,7 +54,9 @@ getJasmineRequireObj().SpyFactory = function(j$) {
} }
if (methods.length === 0 && properties.length === 0) { if (methods.length === 0 && properties.length === 0) {
throw 'createSpyObj requires a non-empty array or object of method names to create spies for'; throw new Error(
'createSpyObj requires a non-empty array or object of method names to create spies for'
);
} }
return obj; return obj;