ShoppingCart
组件现在呈现子组件Items
。此Items
组件的默认prop quantity
设置为整数0
。通过为quantity
传递值10
来覆盖默认支柱。 注意:请记住,向组件添加prop的语法与添加HTML属性的方式类似。但是,由于quantity
的值是一个整数,因此它不会引用引号,但应该用大括号括起来。例如, {100}
。此语法告诉JSX将大括号内的值直接解释为JavaScript。 ShoppingCart
应该呈现组件。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("ShoppingCart").length === 1; })(), "The component ShoppingCart
should render.");'
- text: 该组件Items
应该呈现。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("Items").length === 1; })(), "The component Items
should render.");'
- text: 'Items
组件应具有从ShoppingCart
组件传递的{ quantity: 10 }
的prop。'
testString: 'getUserInput => assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("Items").props().quantity == 10 && getUserInput("index").replace(/ /g,"").includes("Items
component should have a prop of { quantity: 10 }
passed from the ShoppingCart
component.");'
```