From 36427dae9f5bfb399034865a185e4865312970b3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Feb 2014 13:06:47 -0800 Subject: [PATCH] Add toHaveFocus jasmine expectation --- spec/spec-helper.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index c93dcf4fd..e1610748c 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -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