Created
April 24, 2012 21:51
-
-
Save timruffles/2484149 to your computer and use it in GitHub Desktop.
Custom JSTestDriver CSS expectations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> | |
assertCssBoolean = (msg, selector, el, boolean) -> | |
if !el | |
[selector,el] = [msg, selector] | |
msg = "Unexpectedly #{if boolean then "didn't find" else "found"} '#{selector}' in #{$(el).html().truncate(400)}" | |
unless boolean == !!($(el).find(selector).length > 0) | |
fail msg | |
assertHasCss = (msg, selector, el) -> | |
assertCssBoolean msg, selector, el, true | |
assertHasntCss = (msg, selector, el) -> | |
assertCssBoolean msg, selector, el, false | |
assertMatchesSelector = (klass,el) -> | |
assertTrue "Expected #{el} to match #{klass}", $(el).is(klass) | |
assertDoesntMatchSelector = (klass,el) -> | |
assertFalse "Expected #{el} not to match #{klass}", $(el).is(klass) | |
)() | |
assertHasCountCss = (msg, selector, el, expected) -> | |
if !expected | |
[selector,el,expected] = [msg, selector, el] | |
count = $(el).find(selector).length | |
msg = "Found #{count} elements for '#{selector}', expected #{expected} in #{$(el).html().truncate(400)}" | |
count ||= $(el).find(selector).length | |
unless count is expected | |
fail msg | |
assertHasText = (msg, text, el) -> | |
if !el | |
[text, el] = [msg, text] | |
msg = "Could not find '#{text}' in #{$(el).html().truncate(400)}" | |
unless new RegExp(text).test $(el).html() | |
fail msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment