UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

63 lines (42 loc) 1.45 kB
import {expect} from "chai" describe('UUID', function () { class UUID {} before(function (done) { let promises = [] if(!globalThis['crypto']) { promises.push(import("@peculiar/webcrypto").then(m => { globalThis['crypto'] = new m.Crypto(); return true; })) } promises.push(import("../../../source/types/uuid.mjs").then(m => { UUID = m.UUID; return true; })) Promise.all(promises).then(() => { done() }); }); describe('.toString()', function () { it('should return a string', function () { let uuid = new UUID() let result = uuid.toString(); expect(result).is.a('string') expect(result.length).is.equal(36) }); it('test format', function (done) { let uuid = new UUID() let result = uuid.toString(); const regexExp = /^[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i; for (let i = 0; i < 2000; i++) { const u = new UUID().toString(); const r = regexExp.test(u); if (r !== true) { done('no uuid ' + u + ' => ' + r); return; } } done(); }); }); });