There is a simple method, which throws an error:
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 :-)')
}
})
Now I want to do a mocha test for this error. So I came up with this, which is working:
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()
})
Until this point everything is working.
The problem
But I would like to test for the exact error message.
I already tried
expect(expectedError).to.throw(new Meteor.Error('example-error', 'There is no reason for this error :-)'))
But it gives me a failing test:
Error: expected [Function: expectedError] to throw 'Error: There is no reason for this error :-) [example-error]'