-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use helper for get random UUID
We recently used the `randomUUID` method of `crypto`, and added a special configuration for testing with `Jest`. We should have added a BC at that time, because e2e tests of applications can fail if they also do not have the correct Jest configuration. I propose here a better approach, which will avoid a BC and changes on the application side
- Loading branch information
Showing
5 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Returns a random UUID | ||
* @returns {string} a random UUID | ||
*/ | ||
export const getRandomUUID = () => { | ||
if (process.env.NODE_ENV === 'test') { | ||
return 'random-uuid-for-jest' | ||
} | ||
|
||
return window.crypto.randomUUID() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getRandomUUID } from './getRandomUUID' | ||
|
||
describe('getRandomUUID', () => { | ||
it('returns a random uuid', () => { | ||
const uuid = getRandomUUID() | ||
|
||
expect(uuid).toBe('random-uuid-for-jest') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters