1

All of my ember-qunit tests have a similar setup:

moduleFor('route:marketplace-search', 'Marketplace Search route', {
  setup: function() {
    setFixtures();
  },
  teardown: function() {
    App.reset();
  }
});

One of them is throwing an error: Uncaught TypeError: Cannot read property 'length' of null

This can be traced back to the App.reset() line in my marketplace_search_spec.js file:

DEBUG: ------------------------------- ember.js?body=1:14069
DEBUG: Ember      : 1.7.0-beta.1+canary.3d81867a ember.js?body=1:14069
DEBUG: Ember Data : 1.0.0-beta.9+canary.45d196b2 ember.js?body=1:14069
DEBUG: Handlebars : 1.3.0 ember.js?body=1:14069
DEBUG: jQuery     : 1.10.2 ember.js?body=1:14069
DEBUG: ------------------------------- ember.js?body=1:14069
Uncaught TypeError: Cannot read property 'length' of null ember.js?body=1:26529
__exports__.default.ArrayProxy.extend._resetSubControllers ember.js?body=1:26529
__exports__.default.ArrayProxy.extend.willDestroy ember.js?body=1:26542
apply ember.js?body=1:17952
superWrapper ember.js?body=1:17538
DeferredActionQueues.invoke ember.js?body=1:637
DeferredActionQueues.flush ember.js?body=1:687
Backburner.end ember.js?body=1:150
Backburner.run ember.js?body=1:205
apply ember.js?body=1:17955
run ember.js?body=1:16601
handleReset ember.js?body=1:2701
Backburner.run ember.js?body=1:201
apply ember.js?body=1:17955
run ember.js?body=1:16601
apply ember.js?body=1:17955
run.join ember.js?body=1:16643
Namespace.extend.reset ember.js?body=1:2710
moduleFor.teardown marketplace_search_spec.js?body=1:6
_callbacks.teardown ember-qunit.js?body=1:175
Test.teardown teaspoon-qunit.js?body=1:226
(anonymous function) teaspoon-qunit.js?body=1:366
process teaspoon-qunit.js?body=1:1455
(anonymous function) teaspoon-qunit.js?body=1:481

Any ideas why I'm seeing this failure?

Failures:

  1) Marketplace Search route transitions to company.marketplace (1, 1, 2)
     Failure/Error: Teardown failed on transitions to company.marketplace: 'null' is not an object (evaluating 'subControllers.length')

Finished in 7.94400 seconds
127 examples, 1 failure
Dhaulagiri
  • 3,281
  • 24
  • 26
chriscaselas
  • 133
  • 1
  • 6
  • Will you find the line that is breaking? ie `ember.js?body=1:26529` – Amiel Martin Jul 22 '14 at 19:53
  • @AmielMartin [packages/ember-runtime/lib/controllers/array_controller.js#L255](https://github.com/emberjs/ember.js/blob/7a5ab2c1771f71153f4fe5a1fab3a0e3cd615428/packages/ember-runtime/lib/controllers/array_controller.js#L255) – chriscaselas Jul 22 '14 at 20:51
  • 2
    Can you also provide your ArrayController? Any chance you defined `init` without calling `_super`? – Amiel Martin Jul 22 '14 at 21:10
  • @AmielMartin that was exactly it.. so simple! Thanks. It still isn't clear to me when _super is or isn't required. – chriscaselas Jul 23 '14 at 16:23
  • @chriscaselas See note here - http://emberjs.com/api/classes/Ember.ArrayController.html#method_init – jacefarm Aug 24 '14 at 14:42

1 Answers1

3

As @AmielMartin pointed out, my issue was caused by not calling _super in the controller init function I overrode on my ArrayController.

App.MarketplaceSearchController = Ember.ArrayController.extend({
  init: function() {
    this._super();
    // Do stuff here
  }
});
chriscaselas
  • 133
  • 1
  • 6