diff --git a/src/utils/__tests__/clone.spec.ts b/src/utils/__tests__/clone.spec.ts index 19689851..222d858d 100644 --- a/src/utils/__tests__/clone.spec.ts +++ b/src/utils/__tests__/clone.spec.ts @@ -7,6 +7,7 @@ import INTEGER from '#fixtures/integer' import TODAY from '#fixtures/today' import type Vehicle from '#fixtures/types/vehicle' import VEHICLE, { VEHICLE_TAG } from '#fixtures/vehicle' +import * as mlly from '@flex-development/mlly' import testSubject from '../clone' describe('unit:utils/clone', () => { @@ -275,8 +276,22 @@ describe('unit:utils/clone', () => { }) }) + describe('URL', () => { + it('should return deep cloned URL instance', () => { + // Arrange + const value: URL = mlly.toURL('package.json') + + // Act + const result = testSubject(value) + + // Expect + expect(result).to.be.instanceof(URL) + expect(result).to.eql(value).but.not.equal(value) + }) + }) + describe('arrays', () => { - it('should deep cloned array', () => { + it('should return deep cloned array', () => { // Arrange const value: RegExpExecArray = /fo+/g.exec('table football, foosball')! diff --git a/src/utils/clone.ts b/src/utils/clone.ts index a0fbf1f4..19312384 100644 --- a/src/utils/clone.ts +++ b/src/utils/clone.ts @@ -22,6 +22,7 @@ import isRegExp from './is-reg-exp' import isSet from './is-set' import isTypedArray from './is-typed-array' import isUndefined from './is-undefined' +import isURL from './is-url' import properties from './properties' /** @@ -111,6 +112,9 @@ const clone = (value: T): T => { cloned = new Clone(dclone(obj.buffer), obj.byteOffset, obj.length) } + // init cloned url + if (isURL(obj)) cloned = new Clone(obj.href) + // init unknown clone if (isUndefined(cloned) && isFunction(Clone)) cloned = new Clone()