I've got an ember-cli app that's using Ember Data and I'm trying to write an acceptance test that covers the failure case of submitting a form to ask a question. In the test, I'm mocking the response with Pretender to return an errors object, and then asserting that the user is shown a message that lets them know that their submission failed.
The actual assertion that I've written, which checks for an error message to be displayed, is passing. The issue is that I'm also receiving a failure for Error: The backend rejected the commit because it was invalid: {title: can't be blank, body: can't be blank}
.
Is there a way to silence this error during tests? Am I approaching this incorrectly? It's not actually an error in this case. The backend should reject the commit, because that's what I'm trying to cover.
Here's the test:
test('errors are displayed when asking question fails', function() {
server.post('/api/v1/questions', function(request) {
var errors = {
title: ["can't be blank"],
body: ["can't be blank"],
};
return jsonResponse(422, { errors: errors });
});
authenticateSession();
visit('/questions/new');
click('button:contains("Ask")');
andThen(function() {
ok(hasContent('There were some errors with your question.'),
'Error message displayed');
});
});
And the relevant action that's being triggered:
save: function(model) {
var _this = this;
model.save().then(function() {
_this.transitionTo('questions.show', model);
}, function() {
_this.wuphf.danger('There were some errors with your question.');
});
},
And the failure that's popping up: