Skip to content
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

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/e2e-tests/specs/editor/various/taxonomies.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { random } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -19,6 +14,12 @@ import {
const TAG_TOKEN_SELECTOR =
'.components-form-token-field__token-text span:not(.components-visually-hidden)';

function generateRandomNumber() {
Copy link
Member Author

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:

  • It's only used for testing purposes.
  • In each call, it always uses the same arguments, so we're keeping it simple.

// 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 ) );
Copy link
Member Author

Choose a reason for hiding this comment

The 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 ) => {
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down