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

Helper test #15937

Merged
merged 1 commit into from
Dec 7, 2017
Merged

Helper test #15937

merged 1 commit into from
Dec 7, 2017

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Dec 7, 2017

Ref #15933

  • add blueprints
    - [x] fixture helper tests (including mocha unit tests) recommended to do in a separate PR
  • node-tests blueprint tests

@rwjblue
Copy link
Member

rwjblue commented Dec 7, 2017

Will need a rebase on top of the changes from #15938 and #15941

@@ -0,0 +1,12 @@
import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue should we look this up on the container instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/rwjblue/ember-qunit-codemod/blob/master/__testfixtures__/ember-qunit-codemod/native-qunit-to-nested.output.js would suggest no
but I guess in the above scenarios we aren't really testing the helper itself, just the underlying function.

I have found it kind of hard to test class based helpers -- for example:

this.render(hbs`{{my-helper data}}`);

may return objects that don't serialize well.

Would be great if we could do something like

this.render(hbs`{{let actualResult (my-helper data)}}` );
assert.equal(this.actualResult, expectedResult);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're returning something other than a string or number you should probably not use a rendering test and use a "unit" test instead. In any case both tests should probably use the container. Rendering tests do that implicitly and unit tests explicitly.

see also ember-codemods/ember-qunit-codemod#17

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 should I change the unit test to use the container then using factoryFor then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not right now, lets focus on 1:1 for now then we can follow up with a PR that adds usage of owner.factoryFor('helper:foo').create().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed this at length with @krisselden and I believe he is opposed to the public blueprints instantiating helpers outside of the confines of the template layer. I personally disagree, but I don't want to make a change and "sneak it in" without a more thorough discussion. Does that make sense?


await render(hbs`{{foo/bar-baz inputValue}}`);

assert.equal(this.$().text().trim(), '1234');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use this.element.textContent.trim() instead to avoid jQuery

@snewcomer snewcomer force-pushed the helper-test branch 2 times, most recently from 6399b0b to cd6b8d4 Compare December 7, 2017 17:31
return emberGenerateDestroy(['helper-test', 'foo/bar-baz', '--unit'], _file => {
expect(_file('tests/unit/helpers/foo/bar-baz-test.js'))
.to.equal(fixture('helper-test/rfc232-unit.js'));
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found the default as integration to be confusing for helpers. But that's probably just me though 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpers are only logically used from a template, testing them outside of the template layer should be a fairly uncommon thing to do...

@@ -0,0 +1,12 @@
import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 should I change the unit test to use the container then using factoryFor then?

@rwjblue rwjblue merged commit 3fa2562 into emberjs:master Dec 7, 2017
@rwjblue
Copy link
Member

rwjblue commented Dec 7, 2017

Thank you @snewcomer!

@snewcomer snewcomer deleted the helper-test branch December 7, 2017 20:42
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.

4 participants