对组件做出反应的单元测试用例

时间:2019-01-31 06:24:23

标签: javascript reactjs unit-testing react-redux jestjs

我是反应测试的新手。现在,

class search extends React.Component {

  constructor(props) {
    super(props);
    this.staate = {
      search: ''
    }
  }

  onInputChnage = (e) => {
    this.setState({ search: e.target.value });
  }

  render() {

    const { jobs: { content } } = this.props;
    const { search } = this.state;
    const filteredList = content.filter(job => (job.jdName && job.jdName.toLowerCase().includes(search.toLowerCase())) || (job.technology && job.technology.toLowerCase().includes(search.toLowerCase())));

    return (
      <input type="text"
        id="searchJob"
        className="form-control-sm border-0 flex-grow-1"
        value={this.state.search}
        placeholder="Technology / Job title"
        onChange={this.onInputChnage} />
      <i className="fa fa-search search-job"></i>
      )
  }
}

数据就是这样。

this.props.jobs = {
  "content": [{
    "id": "5b7d4a566c5fd00507501051",
    "companyId": null,
    "jdName": "Senior/ Lead UI Developer",
    "jobDescription": null,
    "technology": "java"
  }, {
    "id": "5b7d4a566c5fd005075011",
    "companyId": null,
    "jdName": "ead UI Developer",
    "jobDescription": null,
    "technology": "angular"
  }]
}

因此,在这里我要测试此组件搜索对象。所以,有人可以帮我吗?

0 个答案:

没有答案