Backend rejected commit because it was invalid pen during test

I have an ember-cli application using Ember Data and I'm trying to write an acceptance test that covers the case of a form submission failure to ask a question. In the test, I mock the Pretender answer to return an error object, and then claiming that the user is shown a message that lets them know that their submission failed.

The actual statement that I wrote that checks the error message to be displayed goes through. The problem is that I also get 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 any way to disable this error during tests? Am I getting it wrong? This is actually not a mistake. The backend must reject the commit because this is 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 corresponding action that starts:

 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 error that appears:

Test failure

+6
source share

Source: https://habr.com/ru/post/972973/


All Articles