ember-qunit-codemod
ember-qunit-codemod copied to clipboard
TypeError: helper.compute is not a function
let helper = this.owner.lookup('helper:format-duration');
// before: let helper = this.subject();
let result = helper.compute([convertToMS(59, 'minutes')]);
assert.equal(result, '59 min');
fails with:
TypeError: helper.compute is not a function
Was there a custom subject definition before? Can you share the moduleFor setup invocation?
We for sure do not currently support a custom subject definition. If that was it, then this is roughly the same as https://github.com/rwjblue/ember-qunit-codemod/issues/12.
moduleFor('helper:format-duration', 'Unit | Helper | format duration', {
async beforeEach() {
await this.container.lookup('service:intl').loadAndSetLocale('en');
}
});
I don’t think this is a standard setup here and I’m unsure what exactly is the best path forward. I believe that the default helper tests just import the helpers compute function and test it with “plain qunit”. I presume the setup here is used instead because this is a Ember.Helper.extend() style of helper (as opposed to Ember.Helper.helper(function(){}))?
Ideally, this test would be updated to actually render the helper (e.g. await render(...)), but we should dig a bit more to see why the actual code is failing. It is possible that helper should be added to the array of non-singleton types....
I presume the setup here is used instead because this is a Ember.Helper.extend() style of helper (as opposed to Ember.Helper.helper(function(){}))?
yeah, it's a class-based helper
for future reference, the correct code would be:
let helper = this.owner.factoryFor('helper:format-duration').create();
// before: let helper = this.subject();
let result = helper.compute([convertToMS(59, 'minutes')]);
assert.equal(result, '59 min');
tl;dr factoryFor(...).create() instead of lookup(...).
I made some changes in Ember itself (should be included in 2.17 release next week) to allow the same let helper = this.owner.factoryFor('helper:format-duration').create(); scenario to work in both "class based helper" and "simple helper" cases. See https://github.com/emberjs/ember.js/pull/15848 for a writeup of that...
Based on ^, I am going to update the codemod to transform this.subject() in helper unit tests to the factoryFor(...).create().