Code review? How can I improve this test?

Let me just start off by saying that I’m new at Ember. I’ve tried many times trying to get into Ember but every time, I end up going back to Angular because it just clicks for me. I’m trying really hard not to give in to it this time around.

I’m having a hard time determining what “idiomatic Ember” is. I assumed that one of the main benefits to Ember and their whole convention over configuration policy is that there’s an “Ember way” of doing things. Is that right?

My latest attempt at Ember is using everything that Ember suggests. ember-cli, qunit, ic-ajax, ember data… Yet, I’m still having a lot of trouble figuring out how to put everything together. Is there any recommended reading I could do that would hopefully make things clearer for me? I’ve gone through the Ember and ember-cli guides.

Sorry for the rant… now to my actual question: Can anyone help me improve this test? I’ve hacked it up to hopefully demonstrate what I want to test, but I’m sure this isn’t the right way to do it.

/sunday route:

export default Ember.Route.extend({
  model: function() {
    var _this = this;
    return request('/api/v1/sunday').then(function(data) {
      var bulletin = _this.store.normalize('bulletin', data.bulletin);
      return _this.store.push('bulletin', bulletin);
    });
  }
});

Test:

test('it returns the normalized sunday bulletin', function() {
  expect(5);

  var container = new Ember.Container();
  container.register('store:main', DS.Store);

  var store = container.lookup('store:main');

  var route = this.subject();
  route.store = {
    normalize: function(modelName, model) {
      equal('bulletin', modelName);
      equal('Sunday Service', model.name);
      model.name = 'Normalized ' + model.name;
      return model;
    },
    push: function(modelName, model) {
      equal('bulletin', modelName);
      equal('Normalized Sunday Service', model.name);
      return model;
    }
  };

  route.model().then(function(bulletin) {
    equal('Normalized Sunday Service', bulletin.name);
  });
});

I’m trying to verify that my model hook is

  • fetching data from api/v1/sunday
  • returning a normalized Bulletin object from the json returned from api/v1/sunday.

The code can be found here: https://github.com/openmcac/mcac-js/tree/testing

Is there a cleaner way to do this? Can I use an actual Ember Data store instead of mocking it?

Thanks for your time.