null
的JavaScript函数。需要注意的一件重要事情是,React要求您的函数名称以大写字母开头。这是一个在JSX中分配HTML类的无状态功能组件的示例: //被转换后,<div>将有一个CSS类'customClass'因为JSX组件代表HTML,所以您可以将几个组件放在一起以创建更复杂的HTML页面。这是React提供的组件架构的关键优势之一。它允许您从许多独立的,独立的组件中组合UI。这使得构建和维护复杂的用户界面变得更加容易。
const DemoComponent = function(){
回来(
<div className ='customClass'/>
);
};
MyComponent
的函数。完成此函数,以便返回包含一些文本字符串的单个div
元素。 注意:该文本被视为div
元素的子元素,因此您将无法使用自闭合标记。 MyComponent
应该返回JSX。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.length === 1; })(), "MyComponent
should return JSX.");'
- text: MyComponent
应该返回一个div
元素。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.children().type() === "div" })(), "MyComponent
should return a div
element.");'
- text: div
元素应包含一串文本。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.find("div").text() !== ""; })(), "The div
element should contain a string of text.");'
```