Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Not fully understanding ember-cli-mirage

$
0
0

@melriffe wrote:

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:

// 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:

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:

afterCreate(house, server) {

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

}

And I verified their existence in the test:

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.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles