我是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'
答案 0 :(得分:0)
您的测试期望一个对象匹配一个字符串,这并不是您想要的。您的emailClothingOfferStatus
函数正在返回并且对象的值为'hello'。
您应该能够通过指定希望response.clothingStatus
等于(对字符串值进行声明)来修正测试:
const response = emailClothingOfferStatus(clothingStatus);
return expect(response.clothingStatus).to.eventually.equal('hello')