mercredi 13 janvier 2016

How do you access an ember data store instance in an integration test?

I want to test my component with live data from my API server using ember-data not mock data from a test helper, manual AJAX requests, or from a tool like ember-cli-mirage. Currently all I have in my test is this code:

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('checkbox-group', 'Integration | Component | checkbox group', {
  integration: true
});

test('it renders', function(assert) {
  this.render(hbs`{{checkbox-group}}`);
  assert.equal(this.$().text().trim(), '');
});

What I would like to do is something like this:

test('it renders', function(assert) {
  const store = getStoreFromSomewhere();
  const model = store.find('data').then(() => {
    this.render(hbs`{{checkbox-group data=model}}`);
    // Do testing on component with model from server
  });
});

The problem is I have no idea how to get the store instance, and additionally I don't know how ember does async testing.

The docs have been less than helpful :/. Could someone let me know how to get the store instance, and if that's not possible, another way to do this test with ember-data?




Aucun commentaire:

Enregistrer un commentaire