@@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test"
22
33import {
44 getRandomColor ,
5+ getRandomDigits ,
56 getRandomElement ,
67 getRandomNumber ,
78 getRandomProperty ,
@@ -64,6 +65,36 @@ describe("getRandomNumber", () => {
6465 } )
6566} )
6667
68+ describe ( "getRandomDigits" , ( ) => {
69+ it ( "returns a string" , ( ) => {
70+ const result = getRandomDigits ( 5 )
71+ expect ( typeof result ) . toBe ( "string" )
72+ } )
73+
74+ it ( "returns a string with specified length" , ( ) => {
75+ const result = getRandomDigits ( 10 )
76+ expect ( result . length ) . toBe ( 10 )
77+ } )
78+
79+ it ( "returns different strings on each call" , ( ) => {
80+ const result1 = getRandomDigits ( 5 )
81+ const result2 = getRandomDigits ( 5 )
82+ expect ( result1 ) . not . toBe ( result2 )
83+ } )
84+
85+ it ( "contains only digits" , ( ) => {
86+ const result = getRandomDigits ( 10 )
87+ expect ( result ) . toMatch ( / ^ [ 0 - 9 ] + $ / )
88+ } )
89+
90+ it ( "handles different lengths" , ( ) => {
91+ const short = getRandomDigits ( 1 )
92+ const long = getRandomDigits ( 20 )
93+ expect ( short . length ) . toBe ( 1 )
94+ expect ( long . length ) . toBe ( 20 )
95+ } )
96+ } )
97+
6798describe ( "getRandomElement" , ( ) => {
6899 it ( "returns a value from the array" , ( ) => {
69100 const array = [ 1 , 2 , 3 ]
0 commit comments