我对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'
您的测试期望对象与字符串匹配,这不是您所希望的。你的 emailClothingOfferStatus 函数返回值为“hello”的对象。
emailClothingOfferStatus
您应该能够通过指定所需内容来修复测试 response.clothingStatus 等于(根据字符串值断言):
response.clothingStatus
const response = emailClothingOfferStatus(clothingStatus); return expect(response.clothingStatus).to.eventually.equal('hello')