Skip to content

Commit

Permalink
Merge pull request #147 from rwjblue/add-clearRender
Browse files Browse the repository at this point in the history
Add `clearRender` method to allow testing of willDestroyElement.
  • Loading branch information
rwjblue committed Jan 31, 2016
2 parents f7f77db + e7f6529 commit a9ca224
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_js:
- 'stable'

install:
- npm install -g npm
- npm install -g bower
- npm install --no-optional
- bower install
Expand Down
4 changes: 4 additions & 0 deletions lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export default TestModule.extend({
}
hook.apply(module, Array.prototype.slice.call(arguments, 1));
};

context.clearRender = function() {
module.teardownComponent();
};
},

setupContext: function() {
Expand Down
4 changes: 4 additions & 0 deletions lib/ember-test-helpers/test-module-for-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export default AbstractTestModule.extend({
}
hook.apply(module, Array.prototype.slice.call(arguments, 1));
};

context.clearRender = function() {
module.teardownComponent();
};
},

teardownComponent: function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Ryan Florence",
"Adolfo Builes"
],
"license": "Apache Version 2.0 and MIT",
"license": "(MIT OR Apache-2.0)",
"readmeFilename": "README.md",
"devDependencies": {
"broccoli-babel-transpiler": "^5.4.5",
Expand Down
25 changes: 23 additions & 2 deletions tests/test-module-for-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ moduleForComponent('Component Integration Tests: willDestoryElement', {
var actuallyInDOM = Ember.$.contains(document, this.$()[0]);

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

}
})
});
}
Expand All @@ -594,7 +593,29 @@ moduleForComponent('Component Integration Tests: willDestoryElement', {
test('still in DOM in willDestroyElement', function() {
expect(1);
this.render("{{my-component}}");
});

moduleForComponent('Component Integration Tests: force willDestroyElement via clearRender', {
integration: true,
beforeSetup: function() {
setResolverRegistry({});
}
});

test('still in DOM in willDestroyElement', function() {
expect(1);

let willDestroyCalled = false;
this.register('component:x-button', Ember.Component.extend({
willDestroyElement: function() {
willDestroyCalled = true;
}
}));

this.render("{{x-button}}");
this.clearRender();

ok(willDestroyCalled, 'can add assertions after willDestroyElement is called');
});

if (!hasEmberVersion(2,0)) {
Expand Down
22 changes: 22 additions & 0 deletions tests/test-module-for-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,25 @@ test('still in DOM in willDestroyElement', function() {
this.render("{{my-component}}");

});

moduleForIntegration('TestModuleForIntegration: force willDestroyElement via clearRender', {
beforeSetup: function() {
setResolverRegistry({});
}
});

test('still in DOM in willDestroyElement', function() {
expect(1);

let willDestroyCalled = false;
this.register('component:x-button', Ember.Component.extend({
willDestroyElement: function() {
willDestroyCalled = true;
}
}));

this.render("{{x-button}}");
this.clearRender();

ok(willDestroyCalled, 'can add assertions after willDestroyElement is called');
});

0 comments on commit a9ca224

Please sign in to comment.