How can you test for focus in an AngularJS directive? I would expect the following to work:
describe(\'focus test\', function(){
it(\'should focus element\',
In Jasmine 2, this is now:
beforeEach(function() {
jasmine.addMatchers({
toHaveFocus: function() {
return {
compare: function(actual) {
return {
pass: document.activeElement === actual[0]
};
}
};
}
});
});
Try 'document.activeElement'
instead of ':focus'
. I haven't tested it in karma, but $('document.activeElement')
behaves as desired under standard jQuery.