Skip to content

Commit

Permalink
fix(utils): [clone] URL clone initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Sep 7, 2023
1 parent 5d51d7d commit b34c5d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/utils/__tests__/clone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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')!

Expand Down
4 changes: 4 additions & 0 deletions src/utils/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -111,6 +112,9 @@ const clone = <T>(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()

Expand Down

0 comments on commit b34c5d1

Please sign in to comment.