From 8d99f27be89748225b21dd7b7a62491055f118ea Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 23 Aug 2025 08:19:11 -0700 Subject: [PATCH] Throw an Error rather than a string when createSpyObj is called incorectly --- lib/jasmine-core/jasmine.js | 4 +++- spec/core/SpySpec.js | 6 +++--- src/core/SpyFactory.js | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 10f28f93..d4a5ae4e 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -9964,7 +9964,9 @@ getJasmineRequireObj().SpyFactory = function(j$) { } 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; diff --git a/spec/core/SpySpec.js b/spec/core/SpySpec.js index 323bd5ca..d880d290 100644 --- a/spec/core/SpySpec.js +++ b/spec/core/SpySpec.js @@ -153,7 +153,7 @@ describe('Spies', function() { it('should throw if you do not pass an array or object argument', function() { expect(function() { env.createSpyObj('BaseName'); - }).toThrow( + }).toThrowError( '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() { expect(function() { env.createSpyObj('BaseName', []); - }).toThrow( + }).toThrowError( '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() { expect(function() { env.createSpyObj('BaseName', {}); - }).toThrow( + }).toThrowError( 'createSpyObj requires a non-empty array or object of method names to create spies for' ); }); diff --git a/src/core/SpyFactory.js b/src/core/SpyFactory.js index a9768e1e..512a8912 100644 --- a/src/core/SpyFactory.js +++ b/src/core/SpyFactory.js @@ -54,7 +54,9 @@ getJasmineRequireObj().SpyFactory = function(j$) { } 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;