diff --git a/docs/src/pages/demos/lists/CheckboxListSecondary.js b/docs/src/pages/demos/lists/CheckboxListSecondary.js index 9fc68be9c53b4d..bcb8ca71945def 100644 --- a/docs/src/pages/demos/lists/CheckboxListSecondary.js +++ b/docs/src/pages/demos/lists/CheckboxListSecondary.js @@ -42,9 +42,9 @@ class CheckboxListSecondary extends React.Component { return (
- + {[0, 1, 2, 3].map(value => ( - + diff --git a/packages/material-ui/src/List/List.js b/packages/material-ui/src/List/List.js index 2a50493ef27835..a12395bf22251a 100644 --- a/packages/material-ui/src/List/List.js +++ b/packages/material-ui/src/List/List.js @@ -32,25 +32,27 @@ function List(props) { const { children, classes, - className: classNameProp, + className, component: Component, dense, disablePadding, subheader, ...other } = props; - const className = classNames( - classes.root, - { - [classes.dense]: dense && !disablePadding, - [classes.padding]: !disablePadding, - [classes.subheader]: subheader, - }, - classNameProp, - ); return ( - + {subheader} {children} diff --git a/packages/material-ui/src/List/ListContext.js b/packages/material-ui/src/List/ListContext.js index 65a5b1e7b604de..6e74dad43e9390 100644 --- a/packages/material-ui/src/List/ListContext.js +++ b/packages/material-ui/src/List/ListContext.js @@ -1,5 +1,8 @@ import React from 'react'; +/** + * @ignore - internal component. + */ const ListContext = React.createContext({}); export default ListContext; diff --git a/packages/material-ui/src/List/index.d.ts b/packages/material-ui/src/List/index.d.ts index a0e9c77104d1fe..0e50cb557a6cf1 100644 --- a/packages/material-ui/src/List/index.d.ts +++ b/packages/material-ui/src/List/index.d.ts @@ -1,3 +1,2 @@ export { default } from './List'; export * from './List'; -export { default as ListContext } from './ListContext'; diff --git a/packages/material-ui/src/List/index.js b/packages/material-ui/src/List/index.js index 1172f50a9a5ef8..f455074564439c 100644 --- a/packages/material-ui/src/List/index.js +++ b/packages/material-ui/src/List/index.js @@ -1,2 +1 @@ export { default } from './List'; -export { default as ListContext } from './ListContext'; diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js index 95ffd341503914..da1255eb383bf6 100644 --- a/packages/material-ui/src/ListItem/ListItem.js +++ b/packages/material-ui/src/ListItem/ListItem.js @@ -4,7 +4,7 @@ import classNames from 'classnames'; import withStyles from '../styles/withStyles'; import ButtonBase from '../ButtonBase'; import { isMuiElement } from '../utils/reactHelpers'; -import MergeWithListContext from './MergeWithListContext'; +import MergeListContext from './MergeListContext'; export const styles = theme => ({ /* Styles applied to the (normally root) `component` element. May be wrapped by a `container`. */ @@ -83,7 +83,7 @@ function ListItem(props) { component: componentProp, ContainerComponent, ContainerProps: { className: ContainerClassName, ...ContainerProps } = {}, - dense, + dense: denseProp, disabled, disableGutters, divider, @@ -93,8 +93,8 @@ function ListItem(props) { } = props; return ( - - {({ dense: isDense }) => { + + {({ dense }) => { const children = React.Children.toArray(childrenProp); const hasAvatar = children.some(value => isMuiElement(value, ['ListItemAvatar'])); const hasSecondaryAction = @@ -105,7 +105,7 @@ function ListItem(props) { classes.root, classes.default, { - [classes.dense]: isDense || hasAvatar, + [classes.dense]: dense || hasAvatar, [classes.gutters]: !disableGutters, [classes.divider]: divider, [classes.disabled]: disabled, @@ -154,7 +154,7 @@ function ListItem(props) { return {children}; }} - + ); } diff --git a/packages/material-ui/src/ListItem/ListItem.test.js b/packages/material-ui/src/ListItem/ListItem.test.js index 8144700dabd4f4..433fab71185cb0 100644 --- a/packages/material-ui/src/ListItem/ListItem.test.js +++ b/packages/material-ui/src/ListItem/ListItem.test.js @@ -1,175 +1,188 @@ import React from 'react'; import { assert } from 'chai'; -import { createShallow, getClasses } from '../test-utils'; +import { getClasses, createMount } from '../test-utils'; import ListItemText from '../ListItemText'; import ListItemSecondaryAction from '../ListItemSecondaryAction'; import ListItem from './ListItem'; import ListItemAvatar from '../ListItemAvatar'; import Avatar from '../Avatar'; import ButtonBase from '../ButtonBase'; +import ListContext from '../List/ListContext'; +import MergeListContext from './MergeListContext'; describe('', () => { - let shallow; + let mount; let classes; before(() => { - shallow = createShallow({ dive: true }); classes = getClasses(); + mount = createMount(); + }); + + after(() => { + mount.cleanUp(); }); it('should render a div', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.name(), 'div'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.name(), 'div'); }); it('should render a li', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.name(), 'li'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.name(), 'li'); }); it('should render with the user, root and gutters classes', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.hasClass('woofListItem'), true); - assert.strictEqual(wrapper.hasClass(classes.root), true); - assert.strictEqual(wrapper.hasClass(classes.gutters), true); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass('woofListItem'), true); + assert.strictEqual(listItem.hasClass(classes.root), true); + assert.strictEqual(listItem.hasClass(classes.gutters), true); }); it('should render with the selected class', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.hasClass(classes.selected), true); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.selected), true); }); it('should disable the gutters', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.hasClass(classes.root), true); - assert.strictEqual( - wrapper.hasClass(classes.gutters), - false, - 'should not have the gutters class', - ); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.root), true); + assert.strictEqual(listItem.hasClass(classes.gutters), false); }); it('should use dense class when ListItemAvatar is present', () => { - const wrapper = shallow( - - - - - , - { - context: { - dense: false, - }, - }, + const wrapper = mount( + + + + + + + , ); - - assert.strictEqual(wrapper.hasClass(classes.dense), true); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.dense), true); }); describe('prop: button', () => { it('should render a div', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.props().component, 'div'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.props().component, 'div'); }); }); describe('prop: component', () => { it('should change the component', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.props().component, 'a'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.props().component, 'a'); }); it('should change the component', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.props().component, 'li'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.props().component, 'li'); }); }); describe('context: dense', () => { it('should forward the context', () => { - const wrapper = shallow(); - assert.strictEqual( - wrapper.instance().getChildContext().dense, - false, - 'dense should be false by default', + let context = null; + const wrapper = mount( + + + {options => { + context = options; + }} + + , ); - + assert.strictEqual(context.dense, false); wrapper.setProps({ dense: true }); - assert.strictEqual( - wrapper.instance().getChildContext().dense, - true, - 'dense should be true when set', - ); + assert.strictEqual(context.dense, true); }); }); describe('secondary action', () => { it('should wrap with a container', () => { - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.hasClass(classes.container), true); - assert.strictEqual(wrapper.type(), 'li'); - assert.strictEqual(wrapper.childAt(0).type(), 'div'); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.container), true); + assert.strictEqual(listItem.type(), 'li'); + assert.strictEqual(listItem.childAt(0).type(), 'div'); }); it('should accept a component property', () => { - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.hasClass(classes.container), true); - assert.strictEqual(wrapper.type(), 'li'); - assert.strictEqual(wrapper.childAt(0).type(), 'span'); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.container), true); + assert.strictEqual(listItem.type(), 'li'); + assert.strictEqual(listItem.childAt(0).type(), 'span'); }); it('should accet a button property', () => { - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.hasClass(classes.container), true); - assert.strictEqual(wrapper.type(), 'li'); - assert.strictEqual(wrapper.childAt(0).type(), ButtonBase); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.container), true); + assert.strictEqual(listItem.type(), 'li'); + assert.strictEqual(listItem.childAt(0).type(), ButtonBase); }); it('should accept a ContainerComponent property', () => { - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.hasClass(classes.container), true); - assert.strictEqual(wrapper.type(), 'div'); - assert.strictEqual(wrapper.childAt(0).type(), 'div'); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.container), true); + assert.strictEqual(listItem.type(), 'div'); + assert.strictEqual(listItem.childAt(0).type(), 'div'); }); it('should allow customization of the wrapper', () => { - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.hasClass(classes.container), true); - assert.strictEqual(wrapper.hasClass('bubu'), true); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.hasClass(classes.container), true); + assert.strictEqual(listItem.hasClass('bubu'), true); }); }); describe('prop: focusVisibleClassName', () => { it('should merge the class names', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.props().component, 'div'); + const wrapper = mount(); + const listItem = wrapper.find(MergeListContext).childAt(0); + assert.strictEqual(listItem.props().component, 'div'); assert.strictEqual( - wrapper.props().focusVisibleClassName, + listItem.props().focusVisibleClassName, `${classes.focusVisible} focusVisibleClassName`, ); }); diff --git a/packages/material-ui/src/ListItem/MergeWithListContext.d.ts b/packages/material-ui/src/ListItem/MergeListContext.d.ts similarity index 100% rename from packages/material-ui/src/ListItem/MergeWithListContext.d.ts rename to packages/material-ui/src/ListItem/MergeListContext.d.ts diff --git a/packages/material-ui/src/ListItem/MergeWithListContext.js b/packages/material-ui/src/ListItem/MergeListContext.js similarity index 54% rename from packages/material-ui/src/ListItem/MergeWithListContext.js rename to packages/material-ui/src/ListItem/MergeListContext.js index ee1ddf83e350be..0f9c948a89aca2 100644 --- a/packages/material-ui/src/ListItem/MergeWithListContext.js +++ b/packages/material-ui/src/ListItem/MergeListContext.js @@ -1,18 +1,18 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { ListContext } from '../List'; +import ListContext from '../List/ListContext'; /** - * Consumes a context and passes that context merged with its props - * @param props + * @ignore - internal component. + * + * Consumes a context and passes that context merged with its props. */ -function MergeWithListContext(props) { - const { children, dense } = props; +function MergeListContext(props) { + const { children, dense: denseProp } = props; return ( {context => { - const isDense = dense || context.dense || false; - const childContext = { dense: isDense }; + const childContext = { dense: denseProp || context.dense || false }; return ( {children(childContext)} @@ -22,9 +22,9 @@ function MergeWithListContext(props) { ); } -MergeWithListContext.propTypes = { +MergeListContext.propTypes = { children: PropTypes.func.isRequired, - dense: PropTypes.bool, + dense: PropTypes.bool.isRequired, }; -export default MergeWithListContext; +export default MergeListContext; diff --git a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js index 9b3f273e9d0604..d90735c1c92097 100644 --- a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js +++ b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import warning from 'warning'; import withStyles from '../styles/withStyles'; -import { ListContext } from '../List'; +import ListContext from '../List/ListContext'; export const styles = theme => ({ /* Styles applied to the root element. */ @@ -25,7 +25,7 @@ export const styles = theme => ({ * This is a simple wrapper to apply the `dense` mode styles to `Avatar`. */ function ListItemAvatar(props) { - const { children, classes, className: classNameProp, ...other } = props; + const { children, classes, className, ...other } = props; return ( @@ -42,7 +42,7 @@ function ListItemAvatar(props) { return React.cloneElement(children, { className: classNames( { [classes.root]: context.dense }, - classNameProp, + className, children.props.className, ), childrenClassName: classNames( diff --git a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js index 43fc4dd18079f2..0accb23686e001 100644 --- a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js +++ b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js @@ -1,38 +1,40 @@ import React from 'react'; import { assert } from 'chai'; import consoleErrorMock from 'test/utils/consoleErrorMock'; -import { createShallow, getClasses } from '../test-utils'; +import { createMount, getClasses } from '../test-utils'; import Avatar from '../Avatar'; import ListItemAvatar from './ListItemAvatar'; +import ListContext from '../List/ListContext'; describe('', () => { - let shallow; + let mount; let classes; before(() => { - shallow = createShallow({ dive: true }); + mount = createMount(); classes = getClasses( , - { context: { dense: true } }, ); }); + after(() => { + mount.cleanUp(); + }); + it('should render with the user and root classes', () => { - const wrapper = shallow( - - - , - { - context: { - dense: true, - }, - }, + const wrapper = mount( + + + + + , ); - assert.strictEqual(wrapper.hasClass('foo'), true); - assert.strictEqual(wrapper.hasClass('bar'), true); - assert.strictEqual(wrapper.hasClass(classes.root), true); + const avatar = wrapper.find(Avatar); + assert.strictEqual(avatar.hasClass('foo'), true); + assert.strictEqual(avatar.hasClass('bar'), true); + assert.strictEqual(avatar.hasClass(classes.root), true); }); describe('List', () => { @@ -45,22 +47,19 @@ describe('', () => { }); it('should render an Avatar', () => { - const wrapper = shallow( - - - , - { - context: { - dense: true, - }, - }, + const wrapper = mount( + + + + + , ); - assert.strictEqual(wrapper.type(), Avatar); + assert.strictEqual(wrapper.type(), ListItemAvatar); assert.strictEqual(consoleErrorMock.callCount(), 0); }); it('should warn in a wrong context', () => { - shallow( + mount( , diff --git a/packages/material-ui/src/ListItemText/ListItemText.js b/packages/material-ui/src/ListItemText/ListItemText.js index 07043f03b22ae4..ab06922bc692a6 100644 --- a/packages/material-ui/src/ListItemText/ListItemText.js +++ b/packages/material-ui/src/ListItemText/ListItemText.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import withStyles from '../styles/withStyles'; import Typography from '../Typography'; +import ListContext from '../List/ListContext'; export const styles = theme => ({ /* Styles applied to the root element. */ @@ -40,7 +41,7 @@ export const styles = theme => ({ textDense: {}, }); -function ListItemText(props, context) { +function ListItemText(props) { const { children, classes, @@ -53,53 +54,58 @@ function ListItemText(props, context) { secondaryTypographyProps, ...other } = props; - const { dense } = context; - let primary = primaryProp != null ? primaryProp : children; - if (primary != null && primary.type !== Typography && !disableTypography) { - primary = ( - - {primary} - - ); - } + return ( + + {({ dense }) => { + let primary = primaryProp != null ? primaryProp : children; + if (primary != null && primary.type !== Typography && !disableTypography) { + primary = ( + + {primary} + + ); + } - let secondary = secondaryProp; - if (secondary != null && secondary.type !== Typography && !disableTypography) { - secondary = ( - - {secondary} - - ); - } + let secondary = secondaryProp; + if (secondary != null && secondary.type !== Typography && !disableTypography) { + secondary = ( + + {secondary} + + ); + } - return ( -
- {primary} - {secondary} -
+ return ( +
+ {primary} + {secondary} +
+ ); + }} +
); } @@ -154,8 +160,4 @@ ListItemText.defaultProps = { inset: false, }; -ListItemText.contextTypes = { - dense: PropTypes.bool, -}; - export default withStyles(styles, { name: 'MuiListItemText' })(ListItemText); diff --git a/packages/material-ui/src/ListItemText/ListItemText.test.js b/packages/material-ui/src/ListItemText/ListItemText.test.js index 6e476a603859dd..3b991eca150439 100644 --- a/packages/material-ui/src/ListItemText/ListItemText.test.js +++ b/packages/material-ui/src/ListItemText/ListItemText.test.js @@ -1,166 +1,177 @@ import React from 'react'; import { assert } from 'chai'; -import { createShallow, getClasses } from '../test-utils'; +import { getClasses, createMount } from '../test-utils'; import Typography from '../Typography'; import ListItemText from './ListItemText'; describe('', () => { - let shallow; + let mount; let classes; before(() => { - shallow = createShallow({ dive: true }); + mount = createMount(); classes = getClasses(); }); + after(() => { + mount.cleanUp(); + }); + it('should render a div', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.name(), 'div'); - assert.strictEqual(wrapper.hasClass(classes.root), true); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.name(), 'div'); + assert.strictEqual(listItemText.hasClass(classes.root), true); }); it('should render with the user and root classes', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.hasClass('woofListItemText'), true); - assert.strictEqual(wrapper.hasClass(classes.root), true); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.hasClass('woofListItemText'), true); + assert.strictEqual(listItemText.hasClass(classes.root), true); }); it('should render with inset class', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.hasClass(classes.inset), true); - assert.strictEqual(wrapper.hasClass(classes.root), true); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.hasClass(classes.inset), true); + assert.strictEqual(listItemText.hasClass(classes.root), true); }); it('should render with no children', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.children().length, 0); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.children().length, 0); }); describe('prop: primary', () => { it('should render primary text', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.children().length, 1); - assert.strictEqual(wrapper.childAt(0).type(), Typography); - assert.strictEqual(wrapper.childAt(0).props().variant, 'subheading'); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.children().length, 1); + assert.strictEqual(listItemText.childAt(0).type(), Typography); + assert.strictEqual(listItemText.childAt(0).props().variant, 'subheading'); assert.strictEqual( wrapper .childAt(0) .children() - .equals('This is the primary text'), - true, - 'should have the primary text', + .text(), + 'This is the primary text', ); }); it('should use the primary node', () => { const primary = ; - const wrapper = shallow(); + const wrapper = mount(); assert.strictEqual(wrapper.contains(primary), true); }); it('should use the children prop as primary node', () => { const primary = ; - const wrapper = shallow({primary}); + const wrapper = mount({primary}); assert.strictEqual(wrapper.contains(primary), true); }); it('should read 0 as primary', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.childAt(0).type(), Typography); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(0).type(), Typography); }); }); describe('prop: secondary', () => { it('should render secondary text', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.children().length, 1, 'should have 1 child'); - assert.strictEqual(wrapper.childAt(0).type(), Typography); - assert.strictEqual(wrapper.childAt(0).props().color, 'textSecondary'); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.children().length, 1, 'should have 1 child'); + assert.strictEqual(listItemText.childAt(0).type(), Typography); + assert.strictEqual(listItemText.childAt(0).props().color, 'textSecondary'); assert.strictEqual( - wrapper + listItemText .childAt(0) .children() - .equals('This is the secondary text'), - true, + .text(), + 'This is the secondary text', ); }); it('should use the secondary node', () => { const secondary = ; - const wrapper = shallow(); + const wrapper = mount(); assert.strictEqual(wrapper.contains(secondary), true); }); it('should read 0 as secondary', () => { - const wrapper = shallow(); - assert.strictEqual(wrapper.childAt(0).type(), Typography); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(0).type(), Typography); }); }); describe('prop: disableTypography', () => { it('should wrap children in `` by default', () => { - const wrapper = shallow( + const wrapper = mount( , ); - - assert.strictEqual(wrapper.children().length, 2); - assert.strictEqual(wrapper.childAt(0).type(), Typography); - assert.strictEqual(wrapper.childAt(0).props().variant, 'subheading'); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.children().length, 2); + assert.strictEqual(listItemText.childAt(0).type(), Typography); + assert.strictEqual(listItemText.childAt(0).props().variant, 'subheading'); assert.strictEqual( - wrapper + listItemText .childAt(0) .children() - .equals('This is the primary text'), - true, + .text(), + 'This is the primary text', ); - assert.strictEqual(wrapper.childAt(1).type(), Typography); - assert.strictEqual(wrapper.childAt(1).props().color, 'textSecondary'); + assert.strictEqual(listItemText.childAt(1).type(), Typography); + assert.strictEqual(listItemText.childAt(1).props().color, 'textSecondary'); assert.strictEqual( - wrapper + listItemText .childAt(1) .children() - .equals('This is the secondary text'), - true, - 'should have the secondary text', + .text(), + 'This is the secondary text', ); }); it('should render JSX children', () => { const primaryChild =

This is the primary text

; const secondaryChild =

This is the secondary text

; - const wrapper = shallow( + const wrapper = mount( , ); - assert.strictEqual(wrapper.childAt(0).equals(primaryChild), true); - assert.strictEqual(wrapper.childAt(1).equals(secondaryChild), true); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(0).equals(primaryChild), true); + assert.strictEqual(listItemText.childAt(1).equals(secondaryChild), true); }); }); it('should render primary and secondary text', () => { - const wrapper = shallow( + const wrapper = mount( , ); - - assert.strictEqual(wrapper.children().length, 2); - assert.strictEqual(wrapper.childAt(0).type(), Typography); - assert.strictEqual(wrapper.childAt(0).props().variant, 'subheading'); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.children().length, 2); + assert.strictEqual(listItemText.childAt(0).type(), Typography); + assert.strictEqual(listItemText.childAt(0).props().variant, 'subheading'); assert.strictEqual( - wrapper + listItemText .childAt(0) .children() - .equals('This is the primary text'), - true, + .text(), + 'This is the primary text', ); - assert.strictEqual(wrapper.childAt(1).type(), Typography); - assert.strictEqual(wrapper.childAt(1).props().color, 'textSecondary'); + assert.strictEqual(listItemText.childAt(1).type(), Typography); + assert.strictEqual(listItemText.childAt(1).props().color, 'textSecondary'); assert.strictEqual( - wrapper + listItemText .childAt(1) .children() - .equals('This is the secondary text'), - true, + .text(), + 'This is the secondary text', ); }); @@ -169,23 +180,24 @@ describe('', () => { primary: 'GeneralText', secondary: 'SecondaryText', }; - const wrapper = shallow( + const wrapper = mount( , ); + const listItemText = wrapper.childAt(0).childAt(0); assert.strictEqual( - wrapper + listItemText .childAt(0) .props() .className.includes('GeneralText'), true, ); assert.strictEqual( - wrapper + listItemText .childAt(1) .props() .className.includes('SecondaryText'), @@ -196,31 +208,32 @@ describe('', () => { it('should not re-wrap the element', () => { const primary = This is the primary text; const secondary = This is the secondary text; - const wrapper = shallow(); - assert.strictEqual(wrapper.childAt(0).props().children, primary.props.children); - assert.strictEqual(wrapper.childAt(1).props().children, secondary.props.children); + const wrapper = mount(); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(0).props().children, primary.props.children); + assert.strictEqual(listItemText.childAt(1).props().children, secondary.props.children); }); it('should pass primaryTypographyProps to primary Typography component', () => { - const wrapper = shallow( + const wrapper = mount( , ); - - assert.strictEqual(wrapper.childAt(0).props().color, 'inherit'); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(0).props().color, 'inherit'); }); it('should pass secondaryTypographyProps to secondary Typography component', () => { - const wrapper = shallow( + const wrapper = mount( , ); - - assert.strictEqual(wrapper.childAt(1).props().color, 'inherit'); + const listItemText = wrapper.childAt(0).childAt(0); + assert.strictEqual(listItemText.childAt(1).props().color, 'inherit'); }); });