How do you test computed properties on ED relationships?


#1

Hello

I’m wondering what the current best practice is for testing relationships using ember-qunit. Currently, given a model like:

App.FeedbackItem = DS.Model.extend({
  message: DS.attr('string'),
  children: DS.hasMany('feedback_item', {inverse:"parent", async: true}),
  parent: DS.belongsTo('feedback_item', {inverse:"children"} ),

  isRoot: Ember.computed.none('parent')
});

I’d like to test the functionality of the isRoot computed property, and I’m doing so like this:

test('isRoot - child isRoot is false', function() {
  expect(2);
  var parent = this.subject({
    id: 1,
    message: 'World Explodes.'
  });
  
  var _store = this.store();  

  Ember.run(function(){
    _store.push('feedback_item', { id: 2, message: 'child', parent: 1});
  });

  andThen( function(){
    _store.find('feedback_item', 2).then(function(child){
      var value = child.get('isRoot');
      console.log(child.get('parent').get('message'));
      equal(value, false, "expected false but was " + value);
      equal(parent.get('isRoot'), true, "expected true but was " + value);
    });    
  });
});

You can try it out in a JSBIN here: http://jsbin.com/rajikike/2/edit (you may see an assertion being thrown on alternate runs, this appears to be bug with either ember-qunit or App.reset().

My question is: how would you test that feature?