代码之家  ›  专栏  ›  技术社区  ›  Steerpike

来自javascript和mocha测试的意外断言错误

  •  0
  • Steerpike  · 技术社区  · 6 年前

    我对javascript和mocha还不熟悉。给定以下代码:

    const emailClothingOfferStatus = emailClothing => {
      let withEmailClothing = {}
      const emailClothingRegex = 'hello';
    
      if(emailClothing){
        withEmailClothing = {validPermStatus: emailClothing}
      }
    
      return request
        .get(`${API_ENDPOINT}/provider`)
        .query(withEmailClothing)
        .then(
          res => {
            if (res.body.validPermStatus.match(emailClothingRegex)) {
              return {
                clothingStatus: (res.body.validPermStatus)
              }
              
             //try/catch block here

    当我打电话给

      const response = emailClothingOfferStatus(clothingStatus);
    
      return expect(response).to.eventually.equal('hello')

    我得到的结果是:

      AssertionError: expected { clothingStatus: 'hello' } to equal 'hello'
    1 回复  |  直到 6 年前
        1
  •  0
  •   Lexis Hanson    6 年前

    您的测试期望对象与字符串匹配,这不是您所希望的。你的 emailClothingOfferStatus 函数返回值为“hello”的对象。

    您应该能够通过指定所需内容来修复测试 response.clothingStatus 等于(根据字符串值断言):

          const response = emailClothingOfferStatus(clothingStatus);
          return expect(response.clothingStatus).to.eventually.equal('hello')
    
    推荐文章