Don’t rely on :focus selector for toHaveFocus matcher

:focus doesn’t work properly when focus is inside the shadow DOM of
an element, but document.activeElement does.
This commit is contained in:
Nathan Sobo 2014-10-16 13:53:17 -06:00
parent e8d7058383
commit 7badd9ba25

View File

@ -219,7 +219,7 @@ addCustomMatchers = (spec) ->
@message = -> return "Expected element '" + @actual + "' or its descendants" + notText + " to have focus."
element = @actual
element = element.get(0) if element.jquery
element.webkitMatchesSelector(":focus") or element.querySelector(":focus")
element is document.activeElement or element.contains(document.activeElement)
toShow: ->
notText = if @isNot then " not" else ""