我正在阅读 ember-cli-mirage 的有关创建模拟响应的文档,但无法弄清楚如何为完全相同的请求测试错误响应。例如:
test("I can view the users", function() {
var users = server.createList('user', 3);
visit('/users');
andThen(function() {
equal( find('li').length, 3 );
equal( find('li:first').text(), users[0].name );
});
});
test("I can view the error if viewing the users returns an error", function() {
// somehow set up an error response (?)
visit('/users');
andThen(function() {
equal( find('#error').length, 1 );
});
});
看起来形成响应的唯一方法是在路线中
this.get('/users', function(db, request) {
if (something based on the request, i guess?) {
return new Mirage.Response(500, {}, {message: 'Oops! Something bad happenned. :('});
} else {
return db.users.insert([
{name: 'Zelda', age: 142},
{name: 'Epona', age: 58},
]);
}
});
海市蜃楼建议如何进行此操作?