import randomId, { idWithUniqueSuffix } from './randomId'; describe('randomId', () => { it('should return a string of default length when no arguments are passed', () => { const result = randomId(); expect(result).toHaveLength(21); }); it('should return a string of specified length when an argument is provided', () => { const result = randomId(10); expect(result).toHaveLength(10); }); it('should return unique values across multiple calls', () => { const sampleSize = 100; const ids = Array.from({ length: sampleSize }, randomId); const uniqueIds = new Set(ids); expect(uniqueIds.size).toEqual(sampleSize); }); }); describe('idWithUniqueSuffix', () => { it('should return an array', () => { const result = idWithUniqueSuffix(); expect(result).toBeInstanceOf(Array); }); it('should return a function (for the second value) that increments the suffix by 1 on each call', () => { const [randomStr, withUniqueSuffix] = idWithUniqueSuffix(); const result1 = withUniqueSuffix(); const result2 = withUniqueSuffix(); const result3 = withUniqueSuffix(); expect(result1).toBe(`${randomStr}-1`); expect(result2).toBe(`${randomStr}-2`); expect(result3).toBe(`${randomStr}-3`); }); });