Download wp-calypso/packages/generate-password/src/test/index.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/generate-password/src/test/index.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/generate-password/src/test/index.ts
-
curl -L -o index.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/generate-password/src/test/index.ts
1.45 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import { webcrypto } from 'node:crypto'; | |
| import { generatePassword, DIGITS, SPECIAL_CHARS, EXTRA_SPECIAL_CHARS } from '../'; | |
| describe( 'generatePassword', () => { | |
| const mockRandomValues = jest.fn( ( array ) => webcrypto.getRandomValues( array ) ); | |
| Object.defineProperty( window, 'crypto', { | |
| value: { | |
| getRandomValues: mockRandomValues, | |
| }, | |
| } ); | |
| describe( '.length', () => { | |
| test( 'should use default length of 24', () => { | |
| expect( generatePassword() ).toHaveLength( 24 ); | |
| } ); | |
| test( 'should respect `length` param', () => { | |
| expect( generatePassword( { length: 12 } ) ).toHaveLength( 12 ); | |
| expect( generatePassword( { length: 1337 } ) ).toHaveLength( 1337 ); | |
| expect( generatePassword( { length: 99 } ) ).toHaveLength( 99 ); | |
| } ); | |
| test( 'should not contain digits', () => { | |
| const pw = generatePassword( { length: 1000, useNumbers: false } ); | |
| expect( pw ).not.toMatch( new RegExp( `[${ DIGITS }]`, 'g' ) ); | |
| } ); | |
| test( 'should not contain special characters', () => { | |
| const pw = generatePassword( { length: 1000, useSpecialChars: false } ); | |
| expect( pw ).not.toMatch( new RegExp( `[${ SPECIAL_CHARS }]`, 'g' ) ); | |
| } ); | |
| test( 'should not contain extra special characters', () => { | |
| const pw = generatePassword( { length: 1000, useExtraSpecialChars: false } ); | |
| expect( pw ).not.toMatch( new RegExp( `[${ EXTRA_SPECIAL_CHARS }]`, 'g' ) ); | |
| } ); | |
| } ); | |
| } ); | |