Merge branch 'main' into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / tests / utils / Utils.test.ts
index 7bee08ac625850cb73f40819d8467f3c176e8b6e..0ed7d6b67a54eea7d96aff3ed2a40c2675a99413 100644 (file)
@@ -1,7 +1,9 @@
+import { version } from 'node:process'
 import { describe, it } from 'node:test'
 
 import { hoursToMilliseconds, hoursToSeconds } from 'date-fns'
 import { expect } from 'expect'
+import { satisfies } from 'semver'
 
 import { Constants } from '../../src/utils/Constants.js'
 import {
@@ -341,14 +343,20 @@ await describe('Utils test suite', async () => {
     const date = new Date()
     expect(clone(date)).toStrictEqual(date)
     expect(clone(date) === date).toBe(false)
+    if (satisfies(version, '>=21.0.0')) {
+      const url = new URL('https://domain.tld')
+      expect(() => clone(url)).toThrowError(new Error('Cannot clone object of unsupported type.'))
+    }
     const map = new Map([['1', '2']])
-    expect(clone(map)).toStrictEqual({})
+    expect(clone(map)).toStrictEqual(map)
+    expect(clone(map) === map).toBe(false)
     const set = new Set(['1'])
-    expect(clone(set)).toStrictEqual({})
+    expect(clone(set)).toStrictEqual(set)
+    expect(clone(set) === set).toBe(false)
     const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]])
-    expect(clone(weakMap)).toStrictEqual({})
+    expect(() => clone(weakMap)).toThrowError(new Error('#<WeakMap> could not be cloned.'))
     const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }])
-    expect(clone(weakSet)).toStrictEqual({})
+    expect(() => clone(weakSet)).toThrowError(new Error('#<WeakSet> could not be cloned.'))
   })
 
   await it('Verify hasOwnProp()', () => {