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

this.subject calls not generating new instances #154

Closed
Asgaroth opened this issue Mar 20, 2015 · 1 comment
Closed

this.subject calls not generating new instances #154

Asgaroth opened this issue Mar 20, 2015 · 1 comment

Comments

@Asgaroth
Copy link

Not sure if the title of the issue is correct, but it seems that calling this.subject is not instantiating a new object.

// component definition
export default Ember.Component.extend({
  attr: null,

  init: function() {
    this._super();
    console.log(this);
  }
});


// tests
moduleForComponent('some-comp', {
  // specify the other units that are required for this test
  // needs: ['component:foo', 'helper:bar']
  beforeEach: function() {
    var componentA = this.subject({attr: 'foo'});
    var componentB = this.subject({attr: 'bar'});
  }
});

Expected in the console:

Class {attr: "foo", _outlets: Object, elementId: "ember205", _state: "preRender", currentState: Object…}
Class {attr: "bar", _outlets: Object, elementId: "ember205", _state: "preRender", currentState: Object…}

Instead got:

Class {attr: "foo", _outlets: Object, elementId: "ember205", _state: "preRender", currentState: Object…}

Note: also happens in a regular test so its not a beforeEach issue

Please let me know if I am just doing something wrong

@rwjblue
Copy link
Member

rwjblue commented Mar 20, 2015

Subject (and the other helpers) are memoized, and will be ran once then the result is cached. This is intentional...

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

2 participants