diff --git a/package-lock.json b/package-lock.json index a8307a4..ac315fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "powerbi-visuals-utils-testutils", - "version": "2.5.0", + "version": "2.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "powerbi-visuals-utils-testutils", - "version": "2.5.0", + "version": "2.6.0", "license": "MIT", "dependencies": { "d3-array": "3.1.1", @@ -7122,7 +7122,8 @@ "version": "1.8.0", "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz", "integrity": "sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==", - "dev": true + "dev": true, + "requires": {} }, "acorn-walk": { "version": "8.2.0", @@ -7171,7 +7172,8 @@ "version": "3.5.2", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", - "dev": true + "dev": true, + "requires": {} }, "ansi-regex": { "version": "5.0.1", @@ -8207,7 +8209,8 @@ "version": "8.2.3", "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", - "dev": true + "dev": true, + "requires": {} } } }, @@ -11265,7 +11268,8 @@ "version": "8.5.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", - "dev": true + "dev": true, + "requires": {} }, "xtend": { "version": "4.0.2", diff --git a/package.json b/package.json index 1afdf48..218ff35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "powerbi-visuals-utils-testutils", - "version": "2.5.0", + "version": "2.6.0", "description": "powerbi-visuals-utils-testutils", "main": "lib/index.js", "module": "lib/index.js", diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 03d5bd4..29fa4fa 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -36,10 +36,9 @@ function each(element: JQuery | HTMLElement, fn: (i: number, el: HTMLElement) => } } -function uuid() { - const buf = new Uint8Array(1); - window.crypto.getRandomValues(buf); - return buf[0]; +export function getUuid() { + const uuid = (window.crypto as any).randomUUID(); + return uuid; } @@ -47,7 +46,7 @@ export function testDom(height: number | string, width: number | string): HTMLEl let element: HTMLElement = document.createElement("div"), heightWithUnits: string = isFinite( Number(height) ) ? `${Number(height)}px` : String(height), widthWithUnits: string = isFinite( Number(width) ) ? `${Number(width)}px` : String(width), - id = "item" + uuid(); + id = "item_" + getUuid(); element.id = id; element.style.height = heightWithUnits; diff --git a/test/helpers/helpersTest.ts b/test/helpers/helpersTest.ts index cd99df4..6b5ac24 100644 --- a/test/helpers/helpersTest.ts +++ b/test/helpers/helpersTest.ts @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -import { testDom, getRandomNumber, getRandomNumbers } from "../../src/helpers/helpers"; +import { testDom, getRandomNumber, getRandomNumbers, getUuid } from "../../src/helpers/helpers"; describe("testDom", () => { it("should return an element", () => { @@ -34,6 +34,21 @@ describe("testDom", () => { }); }); +describe("uuid", () => { + it("should be unique across multiple tests", () => { + const uuids = []; + const testsAmount = 1000; + + for (let i = 0; i < testsAmount; i++) { + uuids.push(getUuid()); + } + + const uniqueUUids = [...new Set(uuids)]; + + expect(uuids.length).toEqual(uniqueUUids.length); + }); +}); + describe("getRandomNumber", () => { it("should return a number between min and max", () => { const min: number = 150,