Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: helper.compute is not a function #17

Open
Turbo87 opened this issue Oct 21, 2017 · 8 comments
Open

TypeError: helper.compute is not a function #17

Turbo87 opened this issue Oct 21, 2017 · 8 comments
Labels

Comments

@Turbo87
Copy link
Collaborator

Turbo87 commented Oct 21, 2017

    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
@Turbo87 Turbo87 added the bug label Oct 21, 2017
@rwjblue
Copy link
Member

rwjblue commented Oct 21, 2017

Was there a custom subject definition before? Can you share the moduleFor setup invocation?

@rwjblue
Copy link
Member

rwjblue commented Oct 21, 2017

We for sure do not currently support a custom subject definition. If that was it, then this is roughly the same as #12.

@Turbo87
Copy link
Collaborator Author

Turbo87 commented Oct 21, 2017

moduleFor('helper:format-duration', 'Unit | Helper | format duration', {
  async beforeEach() {
    await this.container.lookup('service:intl').loadAndSetLocale('en');
  }
});

@rwjblue
Copy link
Member

rwjblue commented Oct 21, 2017

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....

@Turbo87
Copy link
Collaborator Author

Turbo87 commented Oct 21, 2017

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

@Turbo87
Copy link
Collaborator Author

Turbo87 commented Nov 10, 2017

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(...).

@rwjblue
Copy link
Member

rwjblue commented Nov 17, 2017

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 emberjs/ember.js#15848 for a writeup of that...

@rwjblue
Copy link
Member

rwjblue commented Nov 17, 2017

Based on ^, I am going to update the codemod to transform this.subject() in helper unit tests to the factoryFor(...).create().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants