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

Cant set attributes in component test in angle-bracket components #12072

Closed
shaunc opened this issue Aug 13, 2015 · 3 comments
Closed

Cant set attributes in component test in angle-bracket components #12072

shaunc opened this issue Aug 13, 2015 · 3 comments

Comments

@shaunc
Copy link

shaunc commented Aug 13, 2015

Using Ember 1.13.7, with addon generated by ember 1.13.8, I have a component x-foo:

import Ember from 'ember';
import layout from './template';

export default Ember.Component.extend({
  layout: layout,

  didReceiveAttrs() {
    console.log("didReceiveAttrs; foo:", this.getAttr('foo'));
  },
  willRender() {
    console.log("willRender; foo:", this.getAttr('foo'));
  }
});

When I instantiate in a test using angle-bracket notation (with feature flags turned on), I can't set attributes. Using the following test, "didReceiveAttrs" and "willRender" are never called.

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('x-foo', 'Integration | Component | x foo', {
  integration: true
});

test('it renders', function(assert) {
  assert.expect(0);


  // Set any properties with this.set('myProperty', 'value');
  // Handle any actions with this.on('myAction', function(val) { ... });

  this.set('foo', 'bar');
  this.render(hbs`<x-foo foo={{mut foo}} />`);```
  this.set('foo', 'baz');
}

They are called when I run with the following render instead.

this.render(hbs`{{x-foo foo=(mut foo)}}`);

In this case the output in the console is:

didReceiveAttrs; foo: bar
willRender; foo: bar
didReceiveAttrs; foo: baz
willRender; foo: baz```
@rwjblue
Copy link
Member

rwjblue commented Aug 13, 2015

Can you submit a failing test case that we can pull into #12011 so that we can ensure this is fixed there (it may already be fixed though)?

@shaunc
Copy link
Author

shaunc commented Aug 13, 2015

I'm a little bit lost in the source code. I checked out the "glimmer-component" branch, and was looking through it to try to find where I should add a test. There I found tests such as "glimmer components cannot be invoked with curly braces" and "legacy components cannot be invoked with angle brackets".

To hit the bug, I used "ember g component x-foo --pod" to generate the component, which gives it a default template of "{{yield}}" which I didn't change. Does this make it a legacy component? Or a glimmer component? (How is one or the other triggered in user code?)

Also, where do you want me to put the test -- into: "packages/ember-htmlbars/tests/integration/component_invocation_test.js" ?

@locks
Copy link
Contributor

locks commented Apr 17, 2016

I am closing this issue since the story around angle bracket components is being revisited.
Feel free to re-open the issue if you think it's still justified, thank you.

@locks locks closed this as completed Apr 17, 2016
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

No branches or pull requests

3 participants