Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add be to the left of matcher

  • Loading branch information...
commit 56d3ea4cc45aa6cb3d96b765e86029a1cb869baa 1 parent 6faa41c
@joshuaclayton authored
Showing with 39 additions and 0 deletions.
  1. +1 −0  README.markdown
  2. +7 −0 specit.js
  3. +10 −0 specit.tests.js
  4. +21 −0 test.html
View
1  README.markdown
@@ -64,6 +64,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
* beGreaterThanOrEqualTo (checks a number is greater than or equal to another)
* 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)
## Other supported features
View
7 specit.js
@@ -100,6 +100,7 @@
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",
}, message, options = arguments[3];
message = matcherMessages[matcher];
@@ -214,6 +215,12 @@
expected: {value: arguments[0], parse: true},
actual: {value: this, parse: true}});
},
+ beToTheLeftOf: function() {
+ Matcher("beToTheLeftOf", "ok",
+ {assert: $(this).offset().left < $(arguments[0]).offset().left,
+ expected: {value: arguments[0], parse: true},
+ actual: {value: $(this).selector, parse: true}});
+ },
}
});
View
10 specit.tests.js
@@ -256,3 +256,13 @@ describe("SpecIt handling before and after", function() {
$("#crazy:contains(awesome div)").shouldNot(beOnThePage);
});
});
+
+describe("SpecIt should know relative positions", function() {
+ it("should know if an element is to the left of another", function() {
+ $(".left-right-correct .left").should(beToTheLeftOf, ".left-right-correct .right");
+ $(".left-right-correct .text-1").should(beToTheLeftOf, ".left-right-correct .text-2");
+
+ $(".left-right-correct .right").shouldNot(beToTheLeftOf, ".left-right-correct .left");
+ $(".left-right-broken .left").shouldNot(beToTheLeftOf, ".left-right-broken .right");
+ });
+});
View
21 test.html
@@ -7,6 +7,15 @@
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="specit.js"></script>
<script type="text/javascript" src="specit.tests.js"></script>
+ <style type="text/css">
+ .column { float: left; margin: 0 10% 0 0; }
+ .last { margin-right: 0; }
+ .left { background-color: blue; }
+ .right { background-color: red; }
+
+ .column-test { clear: both; border-bottom: 10px solid black; }
+ .column-test .column { height: 50px; }
+ </style>
</head>
<body>
<h1 id="qunit-header">SpecIt</h1>
@@ -14,5 +23,17 @@ <h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div class="workspace"></div>
+ <div class="layout-tests">
+ <div class="left-right-correct column-test">
+ <div class="text-1">Text</div>
+ <div class="text-2" style="margin-left: 1px">Text</div>
+ <div class="column left" style="width: 60%;"></div>
+ <div class="column right last" style="width: 30%;"></div>
+ </div>
+ <div class="left-right-broken column-test">
+ <div class="column left" style="width: 60%;"></div>
+ <div class="column right last" style="width: 50%;"></div>
+ </div>
+ </div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.