Permalink
Browse files

assert.css -> assert.style

  • Loading branch information...
1 parent 9d9625b commit 9cff0f55b7726f6f6cd731015fbc61308ac1f90d @assaf committed Nov 22, 2012
Showing with 23 additions and 21 deletions.
  1. +4 −4 doc/new-assertions.md
  2. +19 −17 lib/zombie/assert.coffee
View
@@ -37,10 +37,6 @@ Fails if no elements found.
Asserts that a cookie with the given name has the expected value.
-`browser.assert.css(selector, style, expected, message)`
-
-Assert that the style property of the selected element(s) the expected value.
-
`browser.assert.element(selector, message)`
Assert that an element matching selector exists.
@@ -90,6 +86,10 @@ Assert that the last page load returned status code 200.
Assert that the last page load returned the expected status code.
+`browser.assert.style(selector, style, expected, message)`
+
+Assert that the style property of the selected element(s) the expected value.
+
`browser.assert.text(selector, expected, message)`
Assert that text content of selected element(s) matche the expected value.
View
@@ -18,15 +18,6 @@ assertMatch = (actual, expected, message)->
class Assert
constructor: (@browser)->
- # Asserts the selected element(s) has the expected CSS class.
- hasClass: (selector, expected, message)->
- elements = @browser.queryAll(selector)
- assert elements.length > 0, "Expected selector '#{selector}' to return one or more elements"
- for element in elements
- classNames = element.className.split(/\s+/)
- assert ~classNames.indexOf(expected),
- message || "Expected element '#{selector}' to have class #{expected}, found #{classNames.join(", ")}"
-
# -- Location/response --
# Asserts that a cookie with the given name has the expected value.
@@ -71,14 +62,6 @@ class Assert
actual = element.getAttribute(name)
assertMatch actual, expected, message
- # Assert that the style property of all elements that match selector has the expected value.
- css: (selector, style, expected, message)->
- elements = @browser.queryAll(selector)
- assert elements.length > 0, "Expected selector '#{selector}' to return one or more elements"
- for element in elements
- actual = element.style[style]
- assertMatch actual, expected, message
-
# Assert that element matching selector exists.
element: (selector, message)->
element = @browser.query(selector)
@@ -106,6 +89,25 @@ class Assert
message ||= "Expected at most #{count.atMost} elements matching '#{selector}', found #{elements.length}"
assert elements.length <= count.atMost, message
+ # Asserts the selected element(s) has the expected CSS class.
+ hasClass: (selector, expected, message)->
+ elements = @browser.queryAll(selector)
+ assert elements.length > 0, "Expected selector '#{selector}' to return one or more elements"
+ for element in elements
+ classNames = element.className.split(/\s+/)
+ assert ~classNames.indexOf(expected),
+ message || "Expected element '#{selector}' to have class #{expected}, found #{classNames.join(", ")}"
+
+ # Asserts the selected element(s) has the expected value for the named style
+ # property.
+ style: (selector, style, expected, message)->
+ elements = @browser.queryAll(selector)
+ assert elements.length > 0, "Expected selector '#{selector}' to return one or more elements"
+ for element in elements
+ actual = element.style[style]
+ assertMatch actual, expected,
+ message || "Expected element '#{selector}' to have style #{style} value of #{expected}, found #{actual}"
+
# Asserts that selected input field (text field, text area, etc) has the expected value.
input: (selector, expected, message)->
elements = @browser.queryAll(selector)

0 comments on commit 9cff0f5

Please sign in to comment.