Browse files

Add matcher for above

  • Loading branch information...
1 parent 20fbe27 commit 0ab6fbe3a02d91806fed648771c53d8f9ef44303 @joshuaclayton committed Jun 7, 2010
Showing with 16 additions and 0 deletions.
  1. +1 −0 README.markdown
  2. +7 −0 specit.js
  3. +8 −0 specit.tests.js
View
1 README.markdown
@@ -66,6 +66,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
* beOnThePage (checks that an element is present on a page)
* beToTheLeftOf (checks that an element is to the left of another element)
* beToTheRightOf (checks that an element is to the right of another element)
+* beAbove (checks that an element is above another element)
## Other supported features
View
7 specit.js
@@ -102,6 +102,7 @@
beEmpty: "Expected {actual} {not} to be empty",
beToTheLeftOf: "Expected {actual} {not} to be to the left of {expected}",
beToTheRightOf: "Expected {actual} {not} to be to the right of {expected}",
+ beAbove: "Expected {actual} {not} to be above {expected}",
}, message, options = arguments[3];
message = matcherMessages[matcher];
@@ -228,6 +229,12 @@
expected: {value: $(arguments[0]).selector, parse: true},
actual: {value: $(this).selector, parse: true}});
},
+ beAbove: function() {
+ Matcher("beAbove", "ok",
+ {assert: $(this).offset().top < $(arguments[0]).offset().top,
+ expected: {value: $(arguments[0]).selector, parse: true},
+ actual: {value: $(this).selector, parse: true}});
+ },
}
});
View
8 specit.tests.js
@@ -273,4 +273,12 @@ describe("SpecIt should know relative positions", function() {
$(".left-right-correct .left").shouldNot(beToTheRightOf, ".left-right-correct .right");
$(".left-right-broken .right").shouldNot(beToTheRightOf, ".left-right-broken .left");
});
+
+ it("should know if an element is to the above", function() {
+ $(".left-right-broken .left").should(beAbove, ".left-right-broken .right");
+ $(".left-right-correct .text-2").shouldNot(beAbove, ".left-right-correct .text-1");
+
+ $(".left-right-correct .left").shouldNot(beAbove, ".left-right-correct .right");
+ $(".left-right-correct .right").shouldNot(beAbove, ".left-right-correct .left");
+ });
});

0 comments on commit 0ab6fbe

Please sign in to comment.