在测试期间处理"后端拒绝提交,因为它无效"

Her*_*ric 6 qunit ember.js ember-data ember-testing ember-cli

我有一个使用Ember Data的ember-cli应用程序,我正在尝试编写验收测试,其中包含提交表单以提问的失败案例.在测试中,我正在使用Pretender模拟响应以返回错误对象,然后断言用户会看到一条消息,让他们知道他们的提交失败.

我写的实际断言正在传递,它会检查要显示的错误消息.问题是我也遇到了失败Error: The backend rejected the commit because it was invalid: {title: can't be blank, body: can't be blank}.

有没有办法在测试期间消除这个错误?我接近这个错误吗?在这种情况下,这实际上不是错误.后端应该拒绝提交,因为这就是我想要覆盖的内容.

这是测试:

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');
  });
});
Run Code Online (Sandbox Code Playgroud)

以及正在触发的相关行动:

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.');
  });
},
Run Code Online (Sandbox Code Playgroud)

突然出现的失败:

测试失败