-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lodash: Refactor away from _.random()
#41634
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { random } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -19,6 +14,12 @@ import { | |
const TAG_TOKEN_SELECTOR = | ||
'.components-form-token-field__token-text span:not(.components-visually-hidden)'; | ||
|
||
function generateRandomNumber() { | ||
// Using `Math.random()` directly is fine in this testing context. | ||
// eslint-disable-next-line no-restricted-syntax | ||
return Math.round( 1 + Math.random() * ( Number.MAX_SAFE_INTEGER - 1 ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're definitely not generating a unique component instance here, which is why we're intentionally disabling this rule. Since this looks like a false alarm, it could present an opportunity to improve the ESLint rule. Not anything urgent or directly related to the purpose of this PR, anyway. |
||
} | ||
|
||
describe( 'Taxonomies', () => { | ||
const canCreatTermInTaxonomy = ( taxonomy ) => { | ||
return page.evaluate( ( _taxonomy ) => { | ||
|
@@ -152,7 +153,7 @@ describe( 'Taxonomies', () => { | |
// Click the tag input field. | ||
await tagInput.click(); | ||
|
||
const tagName = "tag'-" + random( 1, Number.MAX_SAFE_INTEGER ); | ||
const tagName = "tag'-" + generateRandomNumber(); | ||
|
||
// Type the category name in the field. | ||
await tagInput.type( tagName ); | ||
|
@@ -211,7 +212,7 @@ describe( 'Taxonomies', () => { | |
// Click the tag input field. | ||
await tagInput.click(); | ||
|
||
const tagName = 'tag-' + random( 1, Number.MAX_SAFE_INTEGER ); | ||
const tagName = 'tag-' + generateRandomNumber(); | ||
|
||
// Type the category name in the field. | ||
await tagInput.type( tagName ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're intentionally not parametrizing this function, since: