【发布时间】:2018-03-11 00:07:26
【问题描述】:
这几天我一直在与海市蜃楼作斗争,仍然没有想出解决办法。
即使配置非常简单(见下文),只要在验收测试中调用 mirage,它也会以 404 错误代码响应。
当我为我的应用程序提供服务并查看浏览器控制台时,这些调用确实可以正常工作
(Mirage 以 200 状态响应,数据在此处使用我在下面设置的 hello@world.com)。
这是我的 mirage/config.js 文件
// mirage/config.js
export default function() {
this.get('/users', function() {
return {
data: [{
type: 'user',
id: 'first',
attributes: {
email: 'hello@world.com'
}
}]
};
});
}
这是我的 app/routes/home.js
// app/routes/home.js
import Route from '@ember/routing/route';
export default Route.extend({
model() { return this.store.findAll('user'); }
});
这是失败的测试
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
module('Acceptance | home', function(hooks) {
setupApplicationTest(hooks);
test('visiting /home', async function(assert) {
await visit('/home');
assert.equal(currentURL(), '/home');
});
});
带有此消息:
Promise rejected during "visiting /home": Ember Data Request GET /users
returned a 404
Payload (Empty Content-Type)
Not found: /users@ 152 ms
Source:
Error: Ember Data Request GET /users returned a 404
Payload (Empty Content-Type)
Not found: /users
at ErrorClass.EmberError
(http://localhost:7357/assets/vendor.js:24125:25)
at ErrorClass.AdapterError
(http://localhost:7357/assets/vendor.js:157167:15)
at new ErrorClass (http://localhost:7357/assets/vendor.js:157185:22)
at Class.handleResponse
(http://localhost:7357/assets/vendor.js:169227:18)
at ajaxError (http://localhost:7357/assets/vendor.js:169720:25)
at Class.hash.error
(http://localhost:7357/assets/vendor.js:169308:23)
at fire (http://localhost:7357/assets/vendor.js:3607:31)
at Object.fireWith [as rejectWith]
(http://localhost:7357/assets/vendor.js:3737:7)
at done (http://localhost:7357/assets/vendor.js:9646:14)
at XMLHttpRequest.<anonymous>
(http://localhost:7357/assets/vendor.js:9887:9)
谢谢
【问题讨论】:
标签: ember.js ember-data ember-cli-mirage