Search code examples
unit-testingangularjsangular-scenario

angularjs triggerHandler is not firing binded event in unit test


with angularJs 1.0.2 I created simple directive that binds to click event on element.

I tried to unittest it with testacular

var linked;
beforeEach(inject(function($rootScope, $compile) {
    scope = $rootScope.$new();
    var widget_definition = '<a href="path" my-directive="">click here</a>';
    linked = $compile(widget_definition);
}));

it('chceck logic on click', function() {
    var button = linked(scope);
    // this doesnt work so I give up :/
    button.triggerHandler('click');
});

but it tells me that there is no such function defined on button element. but this is already jQ(lite) object and in other tests I can use methods defined for jQlite.

is this a bug in angular??


Solution

  • triggerHandler was added in 1.0.3

    Here's a JSFiddle that doesn't throw an exeception http://jsfiddle.net/jaimem/c5Tfw/1/

    btw, if you are dealing with UI changes you might want to do e2e tests.