Testing for focus an AngularJS directive

前端 未结 2 1849
清歌不尽
清歌不尽 2021-02-05 05:38

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\',         


        
2条回答
  •  情深已故
    2021-02-05 06:19

    In Jasmine 2, this is now:

    beforeEach(function() {
      jasmine.addMatchers({
        toHaveFocus: function() {
          return {
            compare: function(actual) {
              return {
                pass: document.activeElement === actual[0]
              };
            }
          };
        }
      });
    });
    

提交回复
热议问题