Ember has a guide on how to do this here . I will put the code here if the manual changes.
Given this component:
App.MyFooComponent = Ember.Component.extend({ layout:Ember.Handlebars.compile("<button {{action 'doSomething'}}></button>"), actions: { doSomething: function() { this.sendAction('internalAction'); } } });
You have verified the action as follows:
moduleForComponent('my-foo', 'MyFooComponent'); test('trigger external action when button is clicked', function() { // tell our test to expect 1 assertion expect(1); // component instance var component = this.subject(); // component dom instance var $component = this.append(); var targetObject = { externalAction: function() { // we have the assertion here which will be // called when the action is triggered ok(true, 'external Action was called!'); } }; // setup a fake external action to be called when // button is clicked component.set('internalAction', 'externalAction'); // set the targetObject to our dummy object (this // is where sendAction will send its action to) component.set('targetObject', targetObject); // click the button click('button'); });
source share