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

Try: Make class and style tests less brittle. #26079

Conversation

TimothyBJacobs
Copy link
Member

Instead of relying on the exact order of classnames and style attributes,
split each string into an array and assert that they are equal sets which
ignores differences due to order.

This hopefully will fix the test failures occurring on master.

Instead of relying on the exact order of classnames and style attributes,
split each string into an array and assert that they are equal sets which
ignores differences due to order.
@peterwilsoncc
Copy link
Contributor

Similar may be needed in assert_styles_and_classes_match(), although I am not sure why the same assertions are run in both the edited and previous test. They look identical.

explode( ' ', $expected_classes ),
explode( ' ', $class_list )
);
$this->assertEquals(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this isn't assertEqualSets as foo:bar; foo:bart is not the same as foo:bart; foo:bar. Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was actually unintentional 🤦 sorry about that.

But now that you say that, style property order could matter in some circumstances for things like browser fallbacks. So perhaps it should stay that way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyBJacobs Not just browser fallbacks. Although I'd consider it questionable practice, you can do something like padding: 4px; padding-left: 8px, where the left padding will be different depending on the property order.

@TimothyBJacobs
Copy link
Member Author

Similar may be needed in assert_styles_and_classes_match(), although I am not sure why the same assertions are run in both the edited and previous test. They look identical.

It looks like assert_styles_and_classes_match might be unused? My editor isn't picking up any calls to it at least.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confession, I totally read assert_ as test_ and only got it correct because of copy🍝 :)

I presume the assert_styles_and_classes_match is there for anyone using this as a testing library.

LGTM and approving.

@TimothyBJacobs TimothyBJacobs merged commit 2a2097f into WordPress:master Oct 14, 2020
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 14, 2020
@TimothyBJacobs
Copy link
Member Author

Thanks for the review @peterwilsoncc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants