0
votes

Anyone have any good examples of testing Ember data in your own app?

I'm starting to build an app using the Fixtures adapter, which is great. But I want to test my models and make sure everything works properly as I build.

I have QUnit setup and running, but I don't want to write the server side in order to verify that the Data Model makes a call. I'd like to mock out the Adapter and just see if the find method is called and return a new object from it. I'll worry about the server side implementation later.

Any ideas?

This is what I have so far (that doesn't work):

test('MyModel should call find', 1, function(){
  App.TestAdapter = DS.Adapter.extend({
    find: function(store, type, id){
      ok(true, 'calls the find method');
      console.log('find: ', type, id);
    }
  });

  App.Store = DS.Store.extend({
    adapter: 'App.TestAdapater'
  });

  myModel = App.MyModel.createRecord({
    name: 'Test',
    period: 0
  });

  // method that should call .find
  myModel.currentObject();

});
1

1 Answers

1
votes

I ended up going with Konacha.

The biggest part was:

before(function() {
  Ember.run(function() {
    App.initialize();     
  });    
});

afterEach(function() {
  Ember.run(function() {
    App.reset();
  });
});