Add toHaveFocus jasmine expectation

This commit is contained in:
probablycorey
2014-02-04 13:06:47 -08:00
parent 3c90007199
commit 36427dae9f

View File

@@ -159,6 +159,17 @@ addCustomMatchers = (spec) ->
@message = -> return "Expected path '" + @actual + "'" + notText + " to exist."
fs.existsSync(@actual)
toHaveFocus: ->
notText = this.isNot and " not" or ""
if not document.hasFocus()
console.error "Specs will fail because the Dev Tools have focus. To fix this close the Dev Tools or click the spec runner."
@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")
window.keyIdentifierForKey = (key) ->
if key.length > 1 # named key
key