简体   繁体   English

来自Javascript和Mocha测试的意外断言错误

[英]Unexpected assertion error from Javascript and Mocha Test

I'm new to JavaScript and Mocha. 我是JavaScript和Mocha的新手。 Given the following code: 给出以下代码:

 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 

When I call with 当我打电话给

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

do I get the outcome of: 我得到以下结果吗?

  AssertionError: expected { clothingStatus: 'hello' } to equal 'hello' 

Your test is expecting an object to match a string, which isn't quite what you want. 您的测试期望一个对象匹配一个字符串,这并不是您想要的。 Your emailClothingOfferStatus function is returning and object with a value of 'hello'. 您的emailClothingOfferStatus函数正在返回并且对象的值为“ hello”。

You should be able to fix your test by specifying what you want response.clothingStatus to equal (asserting against the string value): 您应该能够通过指定要使response.clothingStatus等于(相对于字符串值)的值来修复测试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM