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

Component not in dom in willDestroyElement #16

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default TestModule.extend({
return subject;
});

_this.teardownSteps.push(function() {
_this.teardownSteps.unshift(function() {
Ember.run(function() {
Ember.tryInvoke(containerView, 'destroy');
});
Expand Down
25 changes: 25 additions & 0 deletions tests/test-module-for-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ var ColorController = Ember.ObjectController.extend({
}.property('model')
});

var BoringColor = Ember.Component.extend({
willDestroyElement: function(){
var stateIndicatesInDOM = (this._state === 'inDOM');
var actuallyInDOM = Ember.$.contains(document, this.$()[0]);

ok((actuallyInDOM === true) && (actuallyInDOM === stateIndicatesInDOM), 'component should still be in the DOM')
}
});

function setupRegistry() {
setResolverRegistry({
'component:x-foo': Ember.Component.extend(),
'component:pretty-color': PrettyColor,
'component:boring-color': BoringColor,
'template:components/pretty-color': Ember.Handlebars.compile('Pretty Color: <span class="color-name">{{name}}</span>'),
'controller:color': ColorController
});
Expand Down Expand Up @@ -206,3 +216,18 @@ test("className", function(){
// div contents directly
equal($.trim($('#ember-testing').text()), 'Pretty Color: red');
});

moduleForComponent('boring-color', 'component:boring-color -- still in DOM in willDestroyElement', {
beforeSetup: function() {
setupRegistry();
},

setup: function() {
this.render();
}
});

test("className", function(){
expect(1)
// the assertion is in the willDestroyElement() hook of the component
});