Javascript和Mocha测试产生意外的断言错误

时间:2018-11-25 18:28:54

标签: javascript mocha chai

我是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 个答案:

答案 0 :(得分:0)

您的测试期望一个对象匹配一个字符串,这并不是您想要的。您的emailClothingOfferStatus函数正在返回并且对象的值为'hello'。

您应该能够通过指定希望response.clothingStatus等于(对字符串值进行声明)来修正测试:

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