Testing for focus an AngularJS directive

独自空忆成欢 提交于 2019-12-03 02:28:40

Try 'document.activeElement' instead of ':focus'. I haven't tested it in karma, but $('document.activeElement') behaves as desired under standard jQuery.

In Jasmine 2, this is now:

beforeEach(function() {
  jasmine.addMatchers({
    toHaveFocus: function() {
      return {
        compare: function(actual) {
          return {
            pass: document.activeElement === actual[0]
          };
        }
      };
    }
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!