Friday, 15 June 2012

ember.js - How to new up a controller that "needs" application? -



ember.js - How to new up a controller that "needs" application? -

before adding "needs" controller looked this

var mycontroller = ember.arraycontroller.extend({ wat: function() { homecoming true; }.property() });

this allowed me write simple unit tests so

test('wat returns true ... huh', function() { var controller = new mycontroller(); var wat = controller.get('wat'); ok(wat); });

but after added "needs" block ...

var mycontroller = ember.arraycontroller.extend({ needs: 'application', wat: function() { homecoming true; }.property() });

the "new up" won't work , qunit / ember throwing error so

"please sure controller instantiated container"

without saying "pull in / utilize ember-qunit" other options have here? can slam in "stub" satisfy container requirement?

with ember-qunit (which i'm not biggest fan of) can grab controller using this.subject() , setting module so:

modulefor('controller:comments', 'comments controller', { needs: ['controller:post'] });

http://emberjs.com/guides/testing/testing-controllers/#toc_testing-controller-needs

if weren't using ember qunit utilize container fetch controller (initialized dependency not nowadays when testing). here's helper:

ember.test.registerhelper('containerlookup', function(app, look) { homecoming app.__container__.lookup(look); } );

and utilize so:

test("root lists 3 colors", function(){ var c = containerlookup('controller:foo'); ok(c.get('controllers.bar.tr')); ok(!c.get('controllers.bar.fa')); });

example: http://emberjs.jsbin.com/tumeko/edit

ember.js ember-testing

No comments:

Post a Comment