X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Futils%2FUtils.test.ts;h=0ed7d6b67a54eea7d96aff3ed2a40c2675a99413;hb=8f9060ba0f4e2e22053ceb34f357bb8a1263d889;hp=7bee08ac625850cb73f40819d8467f3c176e8b6e;hpb=b4c82e730be585cb7d7005d66b781d4a02c18a85;p=e-mobility-charging-stations-simulator.git diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index 7bee08ac..0ed7d6b6 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -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('# could not be cloned.')) const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }]) - expect(clone(weakSet)).toStrictEqual({}) + expect(() => clone(weakSet)).toThrowError(new Error('# could not be cloned.')) }) await it('Verify hasOwnProp()', () => {