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

subject helper in moduleForModel reuses container for all tests #81

Closed
bmac opened this issue Jul 25, 2014 · 5 comments
Closed

subject helper in moduleForModel reuses container for all tests #81

bmac opened this issue Jul 25, 2014 · 5 comments

Comments

@bmac
Copy link
Member

bmac commented Jul 25, 2014

While attempting to debug this jsbin from emberjs/data#2112 I noticed this check seems to cause this.subject() to reuse the same container for all the tests in a module. Is that intentional?

@rwjblue
Copy link
Member

rwjblue commented Jul 29, 2014

Thank you for tracking this down. I'm working on some internal refactoring (mostly build related), and will tackle this once that is done.

@givanse
Copy link

givanse commented Sep 29, 2014

What would be the workaround for this? How do I instantiate my own objects instead of using this.subject?

@shturm
Copy link

shturm commented Nov 11, 2014

Same behavior for testing controllers. As temporary workaround I invoke a function which clears the parent scope (subject) properties which I need. Good to know it's not intentional

@bantic
Copy link
Member

bantic commented Nov 12, 2014

We just ran into an issue that seems related to this where the store instance leaked between tests. In the second test a model.reload() promise was silently failing to ever settle because a check in ED for whether the store isDestroyed or isDestroying returned true (because the store was the same instance as the one that had been destroyed in the previous test).

We worked around it by using this.store() and calling createRecord directly instead of using this.subject:

// bad, could reuse the store instance
var model = this.subject();

// good, avoids reusing store
var model = Ember.run(this, function(){
  return this.store().createRecord('my-model-name', options);
});

@bmac
Copy link
Member Author

bmac commented Mar 29, 2015

Fixed by emberjs/ember-test-helpers#28.

@bmac bmac closed this as completed Mar 29, 2015
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

5 participants