[4.2.0-489] Unit testing controllers - specifically event handlers
One of the promoted advantages of 4.2.0, as per the announcement post, is that controllers can be unit tested.
I have certainly found that I can easily instantiate a controller and unit test the methods without problems. However, I'm at a loss as to how to unit test the event listeners.
Given a controller and Jasmine unit test like this:
Code:
Ext.define("TestApp.controller.TestController", {
extend : 'Ext.app.Controller',
init : function() {
this.control({
'button' : { click : this.onClick }
});
},
onClick : function(btn, e, eOpts) {
console.log("Button was clicked");
}
})
describe("Test Controller", function() {
it("should be able to be created", function() {
var test = Ext.create('TestApp.controller.TestController');
spyOn(test, 'onClick');
test.init();
// Do something _here_ to simulate a button clikc
expect(test.onClick).toHaveBeenCalled();
});
});
what would be the best thing to do to trigger the event handler? Short of instantiating a view class that matches the selector (which would normally be more complex, of course)