# Not fully understanding ember-cli-mirage

**URL:** <https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059>\
**Category:** Testing\
**Created:** [September 17, 2019, 5:52pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059 "2019-09-17T17:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![melriffe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/melriffe/32/13595_2.png) [@melriffe](https://discuss.emberjs.com/u/melriffe)\
**Post date:** [September 17, 2019, 5:52pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/1 "2019-09-17T17:52:30Z")

</div>

Background:

- ember-cli: version 2.18.2
- ember-cli-mirage: version 0.4.10

I’ve been diving into acceptance tests and using Mirage to implement my JSON-API back-end. Everything seemed to be going in the right direction until I ran into an issue where it seems an Mirage endpoint is **not** getting called, as expected.

As a contrived example, I have two models: `house` and `bathroom`. And their `app/models` definitions are:

```nohighlight
// app/models/house.js
export default DS.Model.extend({
  bathrooms: DS.hasMany("bathroom")
});

// app/models/bathroom.js
export default DS.Model.extend({
  house DS.belongsTo("house")
});

```

And, running locally, and debugging with the Ember Inspector, I can see the following snippet resolve as expected:

```nohighlight
bathrooms = house.get("bathrooms");

```

I can see the network request generated is `GET /houses/:id/bathrooms`. However, when I’m running my acceptance test, and trying to debug the same code path `bathrooms` does not get populated as expected even though I have a Mirage endpoint `api.get("/houses/:id/bathrooms", (db, request)...`

I know my bathrooms are getting generated because in my house Mirage factory I have the following:

```nohighlight
afterCreate(house, server) {

  server.create("bathroom", { house });
  server.create("bathroom", { house });

}

```

And I verified their existence in the test:

```nohighlight
const bathroomRecords = server.db.bathrooms;
console.log(bathroomRecords[0]);
expect(bathroomRecords.length).to.equal(2);

```

Even the output looked correct, especially the houseId.

I can’t help but to think I’m missing something, but what that is currently escapes me.

Any assistance will be greatly appreciated. I don’t need the answer, per se, just a location where I can find the answer.

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![samselikoff](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/samselikoff/32/16581_2.png) [@samselikoff](https://discuss.emberjs.com/u/samselikoff)\
**Post date:** [September 18, 2019, 12:07am UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/2 "2019-09-18T00:07:11Z")

</div>

If you haven’t already, you’ll need to call `setupMirage()` in your acceptance tests:

```diff
  import { setupApplicationTest } from 'ember-qunit';
+ import { setupMirage } from 'ember-cli-mirage/test-support';

  module('Acceptance | Homepage test', function(hooks) {
    setupApplicationTest(hooks);
+ setupMirage(hooks);

    test('my first test', async function(assert) {
      // test code
    });
  });

```

[Check out the docs for more info](https://www.ember-cli-mirage.com/docs/testing/acceptance-tests).

In the future if you find Mirage not seeming to work, you can always drop a `console.log` in your `mirage/config.js` or even a route handler to verify that code is getting run.

---

<div class="post-metadata">

**Author:** ![melriffe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/melriffe/32/13595_2.png) [@melriffe](https://discuss.emberjs.com/u/melriffe)\
**Post date:** [September 18, 2019, 3:10pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/3 "2019-09-18T15:10:26Z")

</div>

@samselikoff Thank you for your suggestions. I will double-check Mirage is setup and I’ll add `console.log` statements.

Does it matter that we’re using mocha in this project? I don’t think it does since, using my examples, the API call for `GET /houses/:id` appears to be working.

I’ll report back…

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [September 24, 2019, 1:49pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/4 "2019-09-24T13:49:40Z")

</div>

Another thing I’d look it is whether the `links` of the house record is correct in the Mirage response. If it doesn’t match the one of your actual back-end, this might be the problem you’re facing.

I recommend adding `this.server.logging = true` in the test you’re debugging to see the responses from Mirage handlers. You can then check `links.bathrooms` of the `house`.

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [September 24, 2019, 1:50pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/5 "2019-09-24T13:50:52Z")

</div>

@melriffe This is actually done in the Query params chapter of the Rock and Roll book and I know you’re a reader 🙂 so you can check out an example there.

---

<div class="post-metadata">

**Author:** ![melriffe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/melriffe/32/13595_2.png) [@melriffe](https://discuss.emberjs.com/u/melriffe)\
**Post date:** [September 24, 2019, 5:20pm UTC](https://discuss.emberjs.com/t/not-fully-understanding-ember-cli-mirage/17059/6 "2019-09-24T17:20:11Z")

</div>

> [@balint](#):
>
> @melriffe This is actually done in the Query params chapter of the Rock and Roll book and I know you’re a reader 🙂 so you can check out an example there.

😁 Thanks for the feedback. I’ll definitely have a look at the book. However, as changing priorities are ever a challenge, I’ve had to table this current situation for the moment.
