小编Tar*_*mar的帖子

我如何使用 Jest 酶为 componentDidMount 上的 API 调用编写测试用例

我想为 componentDidMount 上的 await API 调用编写一个测试用例,以获取成功和错误。

我添加了 API 调用的代码行为,请为此建议测试用例实现。

import {apiService} from './../../../_services'
import { Component } from 'react';


class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      contentId: 123,
      userID: 1345
    };
  }
  componentDidMount() {
    this.getMappedContent()
      .then(content => {
        if (content) {
          if (content.contentData && content.contentData.isLocked) {
            if (content.contentData.lockedByEmail !== this.state.userID) {
              this.setState({ isLocked, lockedBy })
            }
          }
          this.setState({users: content.contentData})
        }
      })
      .catch(error => {
      })
  }

  getMappedContent = async () => {
    if (!this.state.contentId) {
      return; …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme

5
推荐指数
0
解决办法
147
查看次数

标签 统计

enzyme ×1

jestjs ×1

reactjs ×1