How do I check if my element has been focussed in a unit test

后端 未结 4 1754
梦毁少年i
梦毁少年i 2020-12-14 18:43

I have the following directive to autofocus a field:

.directive(\'ngAutofocus\', function ($timeout) {
    return {
        restrict: \'A\',
        link: fu         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 18:59

    You can use document.activeElement to check focus. The only downside being that the HTML needs to be added to the document body for this to work.

    https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement

提交回复
热议问题