2
votes

In general I'm trying to test my ember models with jasmine. In Ember Data 1.0.0 we no longer have App.Model.find or App.Model.createRecord. Instead we have this.get('store').find and this.get('store').createRecord('model', {}).

How can I get a handle on the store in my tests?

injecting store

I've looked into injecting it but haven't had luck.

Encompass.inject(this, 'store', 'store');

I think this is because the object I'm injecting into this isn't the right type.

creating store

I've also tried creating a store locally:

describe("A Folder", function() {
  var store = null;
  var folder = null;
  beforeEach(function(){
    Encompass.Store = DS.Store.extend({
      adapter: Encompass.ApplicationAdapter
    });
    store = Encompass.Store.create();
  });

but using the store as in

store.find('folder');

results in TypeError: Cannot call method 'lookupFactory' of undefined

I think this is because the container doesn't exist (in time?)

2

2 Answers

4
votes

Your store is trying to access the container but it isn't present. You will need to create manually. And for each model tested you will need to register in the store using:

container.register('model:folder', Encompass.Folder);

You updated test is the following:

describe("A Folder", function() {
  var store = null;
  var folder = null;
  beforeEach(function(){
    Encompass.Store = DS.Store.extend({
      adapter: Encompass.ApplicationAdapter
    });
    var container = new Ember.Container();
    container.register('model:folder', Encompass.Folder);
    store = Encompass.Store.create({
      container: container 
    });
  });
});
2
votes

If you want your application's store you can just look it up off the container. This is fine to do in your tests, but don't dare do this in production :)

var store = App.__container__.lookup('store:main');