ember-cli-mirage: Routes are not loaded in integration test.
I have the same issue as this question.
I have this error :
Mirage: Your Ember app tried to GET ‘/activities’, but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?
I have this integration test :
/* jshint expr:true */
import {expect} from 'chai';
import {
describeComponent,
it
} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import startMirage from '../../helpers/setup-mirage-for-integration';
describeComponent(
'user-form-choose-course',
'Integration: UserFormChooseCourseComponent',
{
integration: true,
setup: function() {
this.inject.service('store');
startMirage(this.container);
}
},
function () {
it('WIP', function () {
Tiny = {};
server.create('activity', {name: 'Tenis'});
const item = this.get('store').createRecord('subscription');
this.set('item', item);
this.render(hbs`{{user-form-choose-course item=item}}`);
expect(this.$('#subscription0-course')).to.have.length(0);
});
}
);
And this config file :
export default function() {
this.urlPrefix = 'http://localhost:3000';
this.get('/activities', 'activities');
this.post('/activities');
this.del('/activities/:id');
this.patch('/activities/:id');
}
Is there a problem?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (1 by maintainers)
@GCorbel thank you very much for digging! Sounds like this was really frustrating, sorry I haven’t had more time lately to help out.
If your app is making a request to an origin other than the current host, you need to specify it explicitly in your
/mirage/config.jsnamespace. When it wasn’t working, did you see an error?I think the solution here is to import your config and use
urlPrefixandAPI_HOSTto dynamically set Mirage’s namespace.I finally found. Not sure to understand all but I resolved my problem. In my config file, I had
this.urlPrefix = 'http://localhost:3000'and in my config file I hadENV.APP.API_HOST = 'http://localhost:3000';so everything seems to be correct but pretender, in this function, build an anchor to find the host.The first time, when mirage is configuring itself, the url is equal tohttp://locahost:3000/usersand is correct but, when it do the request, the url is/usersso the host found is the current host (http://test.local.com:4200/ in my case). Because it does not found the same host, it does find the same route registry.If I go a step further, the request is not performed on the same host between acceptance and unit test. This line does not provide the same value. It’s undefined for unit test and I don’t know why.
For the moment, I just removed the
urlPrefixandAPI_HOSTfor test and it works. This is probably not the best solution. @samselikoff , you have an idea to fix it? I hope to be clear. It was very hard to debug.Struggling with this too. Seems to be something like mirage gets run in the context of the test runner but not the ember app when run via testem and specifying the host gets them to the right spot.
Sorry I don’t think that’s a very good description, but I don’t really understand it any better than that right now 😕
Here’s a repo with a couple of commits that I was figuring this out https://github.com/chrisortman/ember-cms-frontend/commit/745e28c3feafeee8b5f7f0faa7a554b0a364fd52