Using Test Spies with Components and Delegates


#1

Hi all,

I wonder if anyone might be able to help me out with a best practice on this one…

Basically I’m trying to work out how I can put a test spy in place of a component’s action delegate so I can check if the action is being called when a button is being clicked.

Does anyone have any guidance for me, you lovely people? :slight_smile:


#2

Sorry everyone turns out I worked out the solution to my problem:

  test("delegates its hello action to actionDelegate", function() {
    var actionDelegateSpy;

    Ember.run(function() {
      actionDelegateSpy = sinon.spy();
      var actionDelegate = Ember.ObjectController.extend({
        actions: {
          "hello" : actionDelegateSpy
        }
      }).create();
      controller.set('actionDelegate', actionDelegate);      
    });

    visit("/").click("button")
    .then(function() { 
      equal(actionDelegateSpy.called, true, "Action delegate should be called when hello button pressed");
    });
  });

(controller is set to the index controller somewhere above in the test code).

Sorry to take up eyeballs and bandwidth. (Still, might be useful for other people who are trying to do the same).