Skip to content

Commit

Permalink
Merge pull request #89 from martndemus/support-closure-actions
Browse files Browse the repository at this point in the history
Add support for closure actions in component integration test
  • Loading branch information
rwjblue committed Jul 24, 2015
2 parents 54a6181 + 2a16d1d commit 704e91f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ export default TestModule.extend({
setupComponentIntegrationTest: function() {
var module = this;
var context = this.context;

this.actionHooks = {};

context.dispatcher = Ember.EventDispatcher.create();
context.dispatcher.setup({}, '#ember-testing');
this.actionHooks = {};
context.actions = module.actionHooks;

context.render = function(template) {
if (!template) {
Expand All @@ -111,6 +114,7 @@ export default TestModule.extend({
layout: template,
container: module.container
});

module.component.set('context' ,context);
module.component.set('controller', module);

Expand Down Expand Up @@ -157,7 +161,6 @@ export default TestModule.extend({
}
},


send: function(actionName) {
var hook = this.actionHooks[actionName];
if (!hook) {
Expand All @@ -174,6 +177,4 @@ export default TestModule.extend({
});
}
}


});
21 changes: 21 additions & 0 deletions tests/test-module-for-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var PrettyColor = Ember.Component.extend({
}.property('name')
});


var ColorController = Ember.Controller.extend({
hexa: function() {
switch( this.get('model') ) {
Expand All @@ -39,11 +40,18 @@ var BoringColor = Ember.Component.extend({
}
});

var ChangingColor = Ember.Component.extend({
didInsertElement: function() {
this.attrs.change('foo');
}
});

function setupRegistry() {
setResolverRegistry({
'component:x-foo': Ember.Component.extend(),
'component:pretty-color': PrettyColor,
'component:boring-color': BoringColor,
'component:changing-color': ChangingColor,
'template:components/pretty-color': Ember.Handlebars.compile('Pretty Color: <span class="color-name">{{name}}</span>'),
'controller:color': ColorController
});
Expand Down Expand Up @@ -203,6 +211,19 @@ test("className", function(){
// the assertion is in the willDestroyElement() hook of the component
});


moduleForComponent('changing-color', 'component:changing-color -- handles closure actions', {
integration: true
});

if (!/^1\.(11|12)/.test(Ember.VERSION)) {
test('handles a closure actions', function() {
expect(1);
this.on('colorChange', function(arg) { equal(arg, 'foo'); });
this.render(Ember.Handlebars.compile("{{changing-color change=(action 'colorChange')}}"));
});
}

var testModule;
module('moduleForComponent: can be invoked with only the component name', {
beforeEach: function(assert) {
Expand Down

0 comments on commit 704e91f

Please sign in to comment.