diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 7d994b9a..717d0c2d 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -640,6 +640,8 @@ getJasmineRequireObj().util = function(j$) { // All falsey values are either primitives, `null`, or `undefined. if (!argsAsArray[i] || str.match(primitives)) { clonedArgs.push(argsAsArray[i]); + } else if (str === '[object Date]') { + clonedArgs.push(new Date(argsAsArray[i].valueOf())); } else { clonedArgs.push(j$.util.clone(argsAsArray[i])); } diff --git a/spec/core/UtilSpec.js b/spec/core/UtilSpec.js index f95d92fc..7cf638a4 100644 --- a/spec/core/UtilSpec.js +++ b/spec/core/UtilSpec.js @@ -139,6 +139,32 @@ describe('jasmineUnderTest.util', function() { }); }); + describe('cloneArgs', function() { + it('clones primitives as-is', function() { + expect(jasmineUnderTest.util.cloneArgs([true, false])).toEqual([ + true, + false + ]); + expect(jasmineUnderTest.util.cloneArgs([0, 1])).toEqual([0, 1]); + expect(jasmineUnderTest.util.cloneArgs(['str'])).toEqual(['str']); + }); + + it('clones Regexp objects as-is', function() { + var regex = /match/; + expect(jasmineUnderTest.util.cloneArgs([regex])).toEqual([regex]); + }); + + it('clones Date objects as-is', function() { + var date = new Date(2022, 1, 1); + expect(jasmineUnderTest.util.cloneArgs([date])).toEqual([date]); + }); + + it('clones null and undefined', function() { + expect(jasmineUnderTest.util.cloneArgs([null])).toEqual([null]); + expect(jasmineUnderTest.util.cloneArgs([undefined])).toEqual([undefined]); + }); + }); + describe('getPropertyDescriptor', function() { it('get property descriptor from object', function() { var obj = { prop: 1 }, diff --git a/src/core/util.js b/src/core/util.js index b65a1113..7973ff87 100644 --- a/src/core/util.js +++ b/src/core/util.js @@ -54,6 +54,8 @@ getJasmineRequireObj().util = function(j$) { // All falsey values are either primitives, `null`, or `undefined. if (!argsAsArray[i] || str.match(primitives)) { clonedArgs.push(argsAsArray[i]); + } else if (str === '[object Date]') { + clonedArgs.push(new Date(argsAsArray[i].valueOf())); } else { clonedArgs.push(j$.util.clone(argsAsArray[i])); }