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

Flex tests #192

Merged
merged 7 commits into from
Dec 7, 2017
Merged

Flex tests #192

merged 7 commits into from
Dec 7, 2017

Conversation

chrisronline
Copy link
Contributor

References #177

Adds tests for:

  • FlexGroup
  • FlexGrid
  • FlexItem

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Nice! Had a few suggestions and a question.

className: PropTypes.string,
gutterSize: PropTypes.oneOf(GUTTER_SIZES),
columns: PropTypes.oneOf(COLUMNS).isRequired,
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete this?

describe('props', () => {
test('children', () => {
const component = render(
<EuiFlexGrid {...requiredProps}>
Copy link
Contributor

@cjcenizal cjcenizal Dec 6, 2017

Choose a reason for hiding this comment

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

We can remove the requiredProps from every test except for the first one. We just need to assert that they're passed through in one test and then we can forget about them. This applies to the other suites, too. This will reduce noise in the snapshots.

afterAll(() => {
console.warn = consoleWarn;
console.error = consoleError;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we stub these? Where are we using warn and error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I should have explained. I have a couple of tests that try and pass in invalid property values and I want to ensure those result in a the default react warning. I've done this in the past, where I'll change console.warn and console.error to actually throw exceptions which are catchable and easy to handle in a testing environment.

Do you think there is value in this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that makes a ton of sense! Neat solution! I think this would benefit from being abstracted into a service in src/test. Something like this...

beforeAll(() => {
  startThrowingReactWarnings(console);
});

afterAll(() => {
  stopThrowingReactWarnings(console);
});

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea sounds great!

afterAll(() => {
console.warn = consoleWarn;
console.error = consoleError;
});

describe('EuiFlexGroup', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably update the first test in these suites to pass in some children and verify that they're rendered. Then we can remove the specific children test below.

console.warn = consoleWarn;
console.error = consoleError;
});

describe('EuiFlexItem', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update this test to verify that children are rendered?

@@ -27,4 +39,31 @@ describe('EuiFlexItem', () => {
expect(propType({ grow: value }, `grow`) instanceof Error).toBe(true)
);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a block to test the grow prop, and create snapshot tests for the input values of [true, false, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]? We'll need to update the component to export validGrowNumbers so we can refer to that array when building this array of input values. And we should probably rename it GROW_SIZES for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should that value list match this list?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that would make sense if they were the same.

We want our unit tests to verify that invalid property values will
trigger the default react warning message. It feels easier to capture
that scenario as an actual throwing error so these two utility functions
allow you to do that.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe rephrase this as:

Use this utility to throw errors whenever React complains via the console about things like invalid propTypes. This lets us assert that a propType check works correctly with `toThrow`.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🎾 LGTM! I had one idea.

@chrisronline chrisronline merged commit 4dfaf0b into elastic:master Dec 7, 2017
@chrisronline chrisronline deleted the flex-tests branch December 7, 2017 01:27
@cjcenizal cjcenizal mentioned this pull request Dec 7, 2017
22 tasks
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.

2 participants