jeudi 5 juillet 2018

Ember Mirage not passing model as an ember object

I'm using ember-cli-mirage to try out frontend testing, I can't get around this error:

Uncaught TypeError: template.getProperties is not a function

I'm running this in a component test:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

module('Integration | Component | template-editor', function(hooks) {
  setupRenderingTest(hooks);
  setupMirage(hooks);

  test('it renders', async function(assert) {
    const mockTemplate = server.create('template');
    this.set('mockTemplate', mockTemplate);
    await render(hbs``);
    assert.equal(this.get('template.name'), 1);
  });
});

And the relevant part of my components JS file is this:

export default Component.extend({
    init () {
        this._super(...arguments);
        let template = this.get('template');
        if ( template ) {
            let oldProperties = template.getProperties('body','subject');
            this.set('oldProperties',oldProperties);
        }
    }
});

It would appear that the mirage model is not the object my real life code expects, which is an Ember model.

I seem to have followed the docs so far as this is pretty basic, is there something I'm missing here?

The way I've setup mirage is simply to create a mirage factory for the template and add routes for it in the config:

// mirage/config.js
this.get('/templates');
this.get('/templates/:id');

// mirage/factories/template.js
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
    subject: faker.lorem.sentence,
    insertDatetime: faker.date.past,
    body: faker.lorem.paragraphs
});




Aucun commentaire:

Enregistrer un commentaire