test: fix clone() test for latest node version
[e-mobility-charging-stations-simulator.git] / tests / utils / Utils.test.ts
index 3622d8aec45cb0e80ad81381bf46af96b30b6362..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,9 +343,10 @@ await describe('Utils test suite', async () => {
     const date = new Date()
     expect(clone(date)).toStrictEqual(date)
     expect(clone(date) === date).toBe(false)
-    // The URL object seems to have not enumerable properties
-    const url = new URL('https://domain.tld')
-    expect(clone(url)).toStrictEqual({})
+    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(map)
     expect(clone(map) === map).toBe(false)
@@ -351,9 +354,9 @@ await describe('Utils test suite', async () => {
     expect(clone(set)).toStrictEqual(set)
     expect(clone(set) === set).toBe(false)
     const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]])
-    expect(() => clone(weakMap)).toThrow(new Error('#<WeakMap> could not be cloned.'))
+    expect(() => clone(weakMap)).toThrowError(new Error('#<WeakMap> could not be cloned.'))
     const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }])
-    expect(() => clone(weakSet)).toThrow(new Error('#<WeakSet> could not be cloned.'))
+    expect(() => clone(weakSet)).toThrowError(new Error('#<WeakSet> could not be cloned.'))
   })
 
   await it('Verify hasOwnProp()', () => {