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

[BUGFIX beta] Ensure helpers have a consistent API. #15848

Merged
merged 1 commit into from
Nov 13, 2017

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Nov 10, 2017

Having class based helpers return a different API from "simple" helpers is quite confusing. It makes testing a helper significantly different based on the type of helper, and also makes refactoring from simple to class-based a hazzard.

This change ensures that both types of helper return the same basic interface, and enables us to use output similar to the following regardless of the specific type of helper that was exported:

module('foo | Helper', function(hooks) {
  module('unit tests', function(hooks) {
    setupRenderingTest(hooks);

    test('returns some-value', async function(assert) {
      await render(hbs`{{foo 'input' 'values'}}`);

      assert.equal(this.element.textContent, 'some-value', 'helper works!');
    });
  });

  module('unit tests', function(hooks) {
    setupTest(hooks);

    test('returns some-value', function(assert) {
      let helper = this.owner.factoryFor('helper:foo').create();

      assert.equal(helper.compute(['input', 'values']), 'some-value', 'helper works!');
    });
  });
});

Having class based helpers return a different API from "simple" helpers
is quite confusing. It makes testing a helper significantly different
based on the type of helper, and also makes refactoring from simple to
class-based a hazzard.

This change ensures that both types of helper return the same basic
interface, and enables us to use output similar to the following
regardless of the specific type of helper that was exported:

```js
module('foo | Helper', function(hooks) {
  module('unit tests', function(hooks) {
    setupRenderingTest(hooks);

    test('returns some-value', async function(assert) {
      await render(hbs`{{foo 'input' 'values'}}`);

      assert.equal(this.element.textContent, 'some-value', 'helper works!');
    });
  });

  module('unit tests', function(hooks) {
    setupTest(hooks);

    test('returns some-value', function(assert) {
      let helper = this.owner.factoryFor('helper:foo').create();

      assert.equal(helper.compute(['input', 'values']), 'some-value', 'helper works!');
    });
  });
});
```
@rwjblue rwjblue force-pushed the ensure-helpers-are-consistent branch from fcf661e to f98688e Compare November 10, 2017 22:20
@rwjblue rwjblue merged commit 05a89f0 into emberjs:master Nov 13, 2017
@rwjblue rwjblue deleted the ensure-helpers-are-consistent branch November 13, 2017 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant