-
Notifications
You must be signed in to change notification settings - Fork 7
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
Wc 24/gridlist components #75
Conversation
src/gridList.test.jsx
Outdated
|
||
beforeEach(() => { | ||
gridList = TestUtils.renderIntoDocument(JSX_GridListResponsive); | ||
gridListNode = ReactDOM.findDOMNode(gridList); |
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.
Instead of findDOMNode
we've been trying to use these the TestUtils functions like https://facebook.github.io/react/docs/test-utils.html#findRenderedDOMComponentWithClass for these kinds of tests, where we can. There are definitely still instances where you can't get away from avoiding findDOMNode, but since we are testing the classes components directly applied to the component, this should work. You can do something like
const gridList = TestUtils.findRenderedDOMComponentWithClass(gridList, GridList);
const gridListClassList = gridList.props.className;
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.
What are the advantages of using this TestUtils
method over ReactDOM
?
There are some convenience methods in ReactDOM
that were nice, like node.classList.contains('someClass')
, as opposed to component.props.className.indexOf('someClass') > -1
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.
@eilinora shared a nice article in another PR related to this: http://reactkungfu.com/2015/07/approaches-to-testing-react-components-an-overview/
One of the principles is that you should 'maintain the component abstraction in your tests as long as possible, but no longer', i.e. you should definitely prefer TestUtils
methods that scan the React tree, but if you really need to get details of the DOM, you can drop into the 'real' DOM for some tests. I think one of the challenges of working with React is breaking the mental connection between 'React component tree' and 'DOM tree', and then determining at each step of application development which of those abstractions you are desiging/testing.
The article is good, though - definitely worth your time.
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.
I was mistaken; Jest makes this easy...
expect(someClassList).toContain(aClass);
bump Good to merge? |
src/GridList.jsx
Outdated
const classNames = cx( | ||
'gridList', | ||
{ | ||
[`gridList--has${columns.default}`]: typeof columns.default === 'number', |
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.
prefer to keep your 'type-enforcement' code in one place - since number
is already 'enforced' by the proptypes, I recommend just checking for the existence of the prop rather than the type here
[`gridList--has${columns.default}`]: columns.default // or Boolean(columns.default)
src/GridList.jsx
Outdated
</div> | ||
); | ||
}); | ||
return this.gridListItems; |
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.
given how small the render
method is for this component, I think it would be more direct to just put this renderItems
method inside render
directly rather than requiring engineers to jump up to this method when debugging a render error. The whole JSX block in render
could be tightened up without obscuring things too much:
render() {
// ...
return (
<ul className={classNames} {...other}>
{items.map((item, key) =>
<div key={key} className='gridList-item'>{item}</div>
)}
</ul>
);
}
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.
gonna approve but this would be nice :)
src/GridList.jsx
Outdated
return ( | ||
<ul | ||
className={classNames} | ||
{...other}> |
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.
super obnoxious nitpick on my part can you do >
on new line makes it easier to read
Related issues
Fixes https://meetup.atlassian.net/browse/WC-24
Description
Add
GridList
componentScreenshots (if applicable)