* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
4.5 KiB
4.5 KiB
id, title, challengeType, isRequired, videoUrl, localeTitle
id | title | challengeType | isRequired | videoUrl | localeTitle |
---|---|---|---|---|---|
5a24c314108439a4d4036189 | Change Inline CSS Conditionally Based on Component State | 6 | false | 有条件地改变内联CSS基于组件状态 |
Description
Instructions
3px solid red
。您可以通过在输入中输入文本来尝试。 Tests
tests:
- text: <code>GateKeeper</code>组件应该呈现<code>div</code>元素。
testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(GateKeeper)); return mockedComponent.find('div').length === 1; })());
- text: 应使用设置为空字符串的状态键<code>input</code>初始化<code>GateKeeper</code>组件。
testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(GateKeeper)); return mockedComponent.state().input === ''; })());
- text: <code>GateKeeper</code>组件应呈现<code>h3</code>标记和<code>input</code>标记。
testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(GateKeeper)); return mockedComponent.find('h3').length === 1 && mockedComponent.find('input').length === 1; })());
- text: <code>input</code>标记最初应为<code>border</code>属性的<code>1px solid black</code>样式。
testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(GateKeeper)); return mockedComponent.find('input').props().style.border === '1px solid black'; })());
- text: 如果状态中的输入值超过15个字符,则<code>input</code>标记应使用<code>3px solid red</code>边框进行样式设置。
testString: 'async () => { const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const mockedComponent = Enzyme.mount(React.createElement(GateKeeper)); const simulateChange = (el, value) => el.simulate(''change'', {target: {value}}); let initialStyle = mockedComponent.find(''input'').props().style.border; const state_1 = () => { mockedComponent.setState({input: ''this is 15 char'' }); return waitForIt(() => mockedComponent.find(''input'').props().style.border )}; const state_2 = () => { mockedComponent.setState({input: ''A very long string longer than 15 characters.'' }); return waitForIt(() => mockedComponent.find(''input'').props().style.border )}; const style_1 = await state_1(); const style_2 = await state_2(); assert(initialStyle === ''1px solid black'' && style_1 === ''1px solid black'' && style_2 === ''3px solid red''); }; '
Challenge Seed
class GateKeeper extends React.Component {
constructor(props) {
super(props);
this.state = {
input: "
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({ input: event.target.value })
}
render() {
let inputStyle = {
border: '1px solid black'
};
// change code below this line
// change code above this line
return (
<div>
<h3>Don't Type Too Much:</h3>
<input
type="text"
style={inputStyle}
value={this.state.input}
onChange={this.handleChange} />
</div>
);
}
};
After Test
console.info('after the test');
Solution
// solution required