Testing Components in 2.0


#1

I’ve been trying to get the list-view tests working using the Ember canary build. In many of the tests, the component is instantiated programmatically via “this.subject”. I switched to using the “moduleForComponent” test helper (NB ember-cli-mocha “describeComponent” still references Ember.View), and I’ve changed so that properties are passed in via attrs:

  var view = this.subject({attrs: {
      items: content,
      'cell-layout': layout,
      height: height,
      width: width,
      template: compile('<div class="list-item">{{name}}</div>')
    }});

However, I still can’t use view.setAttr (e.g.) on items because the content is not wrapped in a mutable wrapper.

Is there a suggested “best-practice” here? Should I programmatically wrap content in mut (and how)? I could perhaps instantiate whole as a template, but it seems that there should be a way to programmatically instantiate components in tests.

EDIT: another problem – after instantiation as above, attributes are set:

> view.attrs
Object {items: Array[100], cell-layout: Grid, height: 500, width: 500, template: Object}

However, if I render, the attrs go away:

> view.render()
> view.attrs
Object {}

… yet another problem is that <component>.willRender() is not called by render. This I have worked around, but for testing mutation of attribute I can’t even find the attributes hidden on the instantiated component. If I knew how to create a “mut” helper I could try setting the attribute via update() but in the current implementation I am having trouble figuring out what is happening.