【发布时间】:2017-11-14 21:40:15
【问题描述】:
有一个简单的方法,会报错:
methods.js
insertItem = new ValidatedMethod({
name : 'article.insert.item',
validate: new SimpleSchema({
parent: { type: SimpleSchema.RegEx.Id }
value : { type: String }
}).validator(),
run({ parent, value}) {
var isDisabled = true
if (isDisabled)
throw new Meteor.Error('example-error', 'There is no reason for this error :-)')
}
})
现在我想针对这个错误进行 mocha 测试。所以我想出了这个,它正在工作:
server.test.js
it('should not add item, if element is disabled', (done) => {
const value = 'just a string'
function expectedError() {
insertItem.call(
{
parent: '12345',
value
}
)
}
expect(expectedError).to.throw
done()
})
到目前为止一切正常。
问题
但我想测试一下确切的错误信息。
我已经试过了
expect(expectedError).to.throw(new Meteor.Error('example-error', 'There is no reason for this error :-)'))
但它给了我一个失败的测试:
Error: expected [Function: expectedError] to throw 'Error: There is no reason for this error :-) [example-error]'
【问题讨论】:
标签: javascript unit-testing meteor mocha.js chai