Skip to content

Commit

Permalink
Add matcher for above
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jun 7, 2010
1 parent 20fbe27 commit 0ab6fbe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions specit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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}});
},
}
});

Expand Down
8 changes: 8 additions & 0 deletions specit.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.