2.0 KiB
2.0 KiB
id, challengeType, forumTopicId, title
id | challengeType | forumTopicId | title |
---|---|---|---|
5a24bbe0dba28a8d3cbd4c5e | 6 | 301376 | 在 JSX 中添加注释 |
Description
{/* */}
语法来包裹注释文本。
Instructions
div
元素中的某处添加注释,而不修改现有的h1
或p
元素。
Tests
tests:
- text: 常量<code>JSX</code>应该返回一个<code>div</code>元素。
testString: assert(JSX.type === 'div');
- text: <code>div</code>应该包含一个<code>h1</code>标签作为第一个元素。
testString: assert(JSX.props.children[0].type === 'h1');
- text: <code>div</code>应该包含一个<code>p</code>标签作为第二个元素。
testString: assert(JSX.props.children[1].type === 'p');
- text: 当前的 <code>h1</code> 和 <code>p</code> 元素不能被修改。
testString: assert(JSX.props.children[0].props.children === 'This is a block of JSX' && JSX.props.children[1].props.children === 'Here\'s a subtitle');
- text: <code>JSX</code>应该包含一个注释。
testString: assert(/<div>[\s\S]*{\s*\/\*[\s\S]*\*\/\s*}[\s\S]*<\/div>/.test(code));
Challenge Seed
const JSX = (
<div>
<h1>This is a block of JSX</h1>
<p>Here's a subtitle</p>
</div>
);
After Test
ReactDOM.render(JSX, document.getElementById('root'))
Solution
const JSX = (
<div>
<h1>This is a block of JSX</h1>
{ /* this is a JSX comment */ }
<p>Here's a subtitle</p>
</div>);