@belgoros wrote:
I can’t figure out how to define a route in Mirage
config.js
file in the following situation:
- I have
address
router defined as follows:#router.js Router.map(function() { ... this.route('address'); // it is not nested ...
In
address.js
route handler themodel
hook is defined as follows to hit/shops/:identifier/address
end-point on the API backend side:#routes/address.js export default Route.extend(AuthenticatedRouteMixin, { currentShop: service(), model() { return this.store.queryRecord('address', { shop_identifier: this.get('currentShop.shop').get('identifier')}); }
I tried to define
address
route in Mirageconfig/js
as follows:this.get('/shops'); this.get('/address', (schema, request) => { let shop = schema.shops.where(request.params.shop_identifier); return shop.address; });
but it fails when running the test. Whatever I try, when running
acceptance/address-test.js
, it fails with:Mirage: Error: Your Ember app tried to GET '/shops/43544/address', 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?
Here is the test itself:
#tests/acceptance/address-test.js import { module, test } from 'qunit'; import { visit, currentURL } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import { authenticateSession } from 'ember-simple-auth/test-support'; import setupMirageTest from 'ember-cli-mirage/test-support/setup-mirage'; import { setupWindowMock } from 'ember-window-mock'; module('Acceptance | Address', function(hooks) { setupWindowMock(hooks); setupApplicationTest(hooks); setupMirageTest(hooks); test('Authenticated users can visit /address', async function(assert) { let shop = server.create('shop'); server.create('user', { shop }); server.create('address', { shop }); await authenticateSession({ access_token: 'azerty', token_type: 'Bearer' }); await visit('/address'); assert.equal(currentURL(), '/address', 'user is on the Address page'); }); });
What am I missing?
Posts: 1
Participants: 1