I've been struggling with mirage for the past few days, and still haven't come up with a solution.
Even with a very simplified configuration (see below), mirage responds with a 404 error code whenever it is called within acceptance tests. The calls do work perfectly when I serve my app and look at the browser console (Mirage responds with a 200 status, and the data is here with the hello@world.com
that I setup bellow).
Here's my mirage/config.js file
// mirage/config.js
export default function() {
this.get('/users', function() {
return {
data: [{
type: 'user',
id: 'first',
attributes: {
email: 'hello@world.com'
}
}]
};
});
}
Here's my app/routes/home.js
// app/routes/home.js
import Route from '@ember/routing/route';
export default Route.extend({
model() { return this.store.findAll('user'); }
});
Here's the failing test
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');
});
});
With this message:
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)
Thank you
Aucun commentaire:
Enregistrer un commentaire