mardi 26 mai 2015

EmberJS: Test a Serializer with Store involved using ember-mocha

I am rewriting my yeoman ember project to use ember-cli, and am now stuck on rewriting my serializer test, as Mocha's describeModel function brings in a store ...

import { expect, assert } from 'chai';
import { describeModel,it } from 'ember-mocha';

describeModel('connection','Connection Desc', { needs: ['model:result'] },
  function() {
    it('exists', function() {
      var model = this.subject();
      var store = this.store();
      expect(model).to.be.ok;
    });
});

... but describeModule does not. As a work-around I am manually create a store, but guess that's is not very convinient and am sure there is a more readable way to do so:

import App from '../../../app';
import { expect, assert } from 'chai';
import { describeModule, it } from 'ember-mocha';

describeModule( 'serializer:result', 'Result Serializer', { needs: ['model:result'] },

function() {

  it('convert a single item on a result to a one element array', function(){
    var serializer = this.subject();

    App.ApplicationStore = DS.Store.extend({
      adapter: DS.MochaAdapter
    });
    var store = App.ApplicationStore.create({
      container: this.container
    });

    expect(
      serializer.extractArray( store, store.modelFor('result'), {"results":[]})
    ).to.be.an.instanceOf(Array).and.have.lengthOf(0);
  });
});

There exists the possibility to mock, but mocking every single possible method of the store does not sound tempting.

Is there a shorter way of getting the DS.Store instance (similar to the subject) for the example above?




Aucun commentaire:

Enregistrer un commentaire