Permalink
Browse files

Add completely to the left of matcher

  • Loading branch information...
joshuaclayton committed Jun 7, 2010
1 parent 56d3ea4 commit 0f64ea17ce1a09aaa4d2f11f25f948f8e2d93702
Showing with 20 additions and 2 deletions.
  1. +1 −0 README.markdown
  2. +11 −2 specit.js
  3. +8 −0 specit.tests.js
View
@@ -65,6 +65,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
* beEmpty (checks if an array, object literal, or string is empty)
* beOnThePage (checks that an element is present on a page)
* beToTheLeftOf (checks that an element is to the left of another element)
+* beCompletelyToTheLeftOf (checks that an element is completely to the left of another element)
## Other supported features
View
@@ -100,7 +100,8 @@
beGreaterThanOrEqualTo: "Expected {actual} {not} to be greater than or equal to {expected}",
beOnThePage: "Expected {actual} {not} to be on the page",
beEmpty: "Expected {actual} {not} to be empty",
- beToTheLeftOf: "Expected {actual} {not} to be to the left of",
+ beToTheLeftOf: "Expected {actual} {not} to be to the left of {expected}",
+ beCompletelyToTheLeftOf:"Expected {actual} {not} to be completely to the left of {expected}",
}, message, options = arguments[3];
message = matcherMessages[matcher];
@@ -218,7 +219,15 @@
beToTheLeftOf: function() {
Matcher("beToTheLeftOf", "ok",
{assert: $(this).offset().left < $(arguments[0]).offset().left,
- expected: {value: arguments[0], parse: true},
+ expected: {value: $(arguments[0]).selector, parse: true},
+ actual: {value: $(this).selector, parse: true}});
+ },
+ beCompletelyToTheLeftOf: function() {
+ console.log($(this).offset());
+ console.log($(arguments[0]).offset());
+ Matcher("beCompletelyToTheLeftOf", "ok",
+ {assert: ($(this).offset().left + $(this).width()) < $(arguments[0]).offset().left,
+ expected: {value: $(arguments[0]).selector, parse: true},
actual: {value: $(this).selector, parse: true}});
},
}
View
@@ -265,4 +265,12 @@ describe("SpecIt should know relative positions", function() {
$(".left-right-correct .right").shouldNot(beToTheLeftOf, ".left-right-correct .left");
$(".left-right-broken .left").shouldNot(beToTheLeftOf, ".left-right-broken .right");
});
+
+ it("should know if an element is completely to the left of another", function() {
+ $(".left-right-correct .left").should(beCompletelyToTheLeftOf, ".left-right-correct .right");
+ $(".left-right-correct .text-1").shouldNot(beCompletelyToTheLeftOf, ".left-right-correct .text-2");
+
+ $(".left-right-correct .right").shouldNot(beCompletelyToTheLeftOf, ".left-right-correct .left");
+ $(".left-right-broken .left").shouldNot(beCompletelyToTheLeftOf, ".left-right-broken .right");
+ });
});

0 comments on commit 0f64ea1

Please sign in to comment.