Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

1351 lines (1194 sloc) 87.577 kB
<a href="http://github.com/learnboost/tobi"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
<head>
<title>Tobi</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>body {
margin: 0;
padding: 0;
font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
color: #252519;
}
a {
color: #252519;
}
a:hover {
text-decoration: underline;
color: #19469D;
}
p {
margin: 12px 0;
}
h1, h2, h3 {
margin: 0;
padding: 0;
}
table#source {
width: 100%;
border-collapse: collapse;
}
table#source td:first-child {
padding: 30px 40px 30px 40px;
vertical-align: top;
}
table#source td:first-child,
table#source td:first-child pre {
width: 450px;
}
table#source td:last-child {
padding: 30px 0 30px 40px;
border-left: 1px solid #E5E5EE;
background: #F5F5FF;
}
table#source tr {
border-bottom: 1px solid #E5E5EE;
}
table#source tr.filename {
padding-top: 40px;
border-top: 1px solid #E5E5EE;
}
table#source tr.filename td:first-child {
text-transform: capitalize;
}
table#source tr.filename td:last-child {
font-size: 12px;
}
table#source tr.filename h2 {
margin: 0;
padding: 0;
cursor: pointer;
}
table#source tr.code h1,
table#source tr.code h2,
table#source tr.code h3 {
margin-top: 30px;
font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
font-size: 18px;
}
table#source tr.code h2 {
font-size: 16px;
}
table#source tr.code h3 {
font-size: 14px;
}
table#source tr.code ul {
margin: 15px 0 15px 35px;
padding: 0;
}
table#source tr.code ul li {
margin: 0;
padding: 1px 0;
}
table#source tr.code ul li p {
margin: 0;
padding: 0;
}
table#source tr.code td:first-child pre {
padding: 20px;
}
#ribbon {
position: fixed;
top: 0;
right: 0;
}
code .string { color: #219161; }
code .regexp { color: #219161; }
code .keyword { color: #954121; }
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
<script>
$(function(){
$('tr.code').hide();
$('tr.filename').toggle(function(){
$(this).nextUntil('.filename').fadeIn();
}, function(){
$(this).nextUntil('.filename').fadeOut();
});
});
</script>
</head>
<body>
<table id="source"><tbody><tr><td><h1>Tobi</h1><p>Expressive server-side functional testing with jQuery and jsdom.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/assertions/should.js"><a href="#">should</a></h2></td><td>lib/assertions/should.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Assertion</span> = <span class="variable">require</span>(<span class="string">'should'</span>).<span class="class">Assertion</span>
, <span class="variable">statusCodes</span> = <span class="variable">require</span>(<span class="string">'http'</span>).<span class="class">STATUS_CODES</span>
, <span class="variable">j</span> = <span class="keyword">function</span>(<span class="variable">elem</span>){ <span class="keyword">return</span> <span class="string">'[jQuery '</span> + <span class="variable">i</span>(<span class="variable">elem</span>.<span class="variable">selector</span>.<span class="variable">replace</span>(<span class="regexp">/^ *\* */</span>, <span class="string">''</span>)) + <span class="string">']'</span>; }
, <span class="variable">i</span> = <span class="variable">require</span>(<span class="string">'sys'</span>).<span class="variable">inspect</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Number strings.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">nums</span> = { <span class="number integer">0</span>: <span class="string">'none'</span>, <span class="number integer">1</span>: <span class="string">'one'</span>, <span class="number integer">2</span>: <span class="string">'two'</span>, <span class="number integer">3</span>: <span class="string">'three'</span> };</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return string representation for <code>n</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="variable">n</span>(<span class="variable">n</span>) { <span class="keyword">return</span> <span class="variable">nums</span>[<span class="variable">n</span>] || <span class="variable">n</span>; }</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert text as <code>str</code> or a <code>RegExp</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String | RegExp</em> str</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">text</span> = <span class="keyword">function</span>(<span class="variable">str</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">text</span> = <span class="variable">elem</span>.<span class="variable">text</span>();
<span class="keyword">if</span> (<span class="variable">str</span> <span class="variable">instanceof</span> <span class="class">RegExp</span>) {
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">str</span>.<span class="variable">test</span>(<span class="variable">text</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>)+ <span class="string">' to have text matching '</span> + <span class="variable">i</span>(<span class="variable">str</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' text '</span> + <span class="variable">i</span>(<span class="variable">text</span>) + <span class="string">' to not match '</span> + <span class="variable">i</span>(<span class="variable">str</span>));
} <span class="keyword">else</span> {
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">str</span> == <span class="variable">text</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have text '</span> + <span class="variable">i</span>(<span class="variable">str</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">text</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have text '</span> + <span class="variable">i</span>(<span class="variable">str</span>));
}
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert that many child elements are present via <code>selector</code>.
When negated, &lt;= 1 is a valid length.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">many</span> = <span class="keyword">function</span>(<span class="variable">selector</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">elems</span> = <span class="variable">elem</span>.<span class="variable">find</span>(<span class="variable">selector</span>)
, <span class="variable">len</span> = <span class="variable">elems</span>.<span class="variable">length</span>;
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="this">this</span>.<span class="variable">negate</span> ? <span class="variable">len</span> &<span class="variable">gt</span>; <span class="number integer">1</span> : <span class="variable">len</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have many '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tags, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have many '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tags, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>));
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert that one child element is present via <code>selector</code>
with optional <code>text</code> assertion..</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>String</em> text</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">one</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">text</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">elems</span> = <span class="variable">elem</span>.<span class="variable">find</span>(<span class="variable">selector</span>)
, <span class="variable">len</span> = <span class="variable">elems</span>.<span class="variable">length</span>;
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="number integer">1</span> == <span class="variable">len</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have one '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tag, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have one '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tag, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>));
<span class="keyword">if</span> (<span class="variable">undefined</span> != <span class="variable">text</span>) {
<span class="variable">elems</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">text</span>(<span class="variable">text</span>);
}
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert existance attr <code>key</code> with optional <code>val</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> key</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">attr</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">val</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">attr</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">key</span>);
<span class="keyword">if</span> (!<span class="variable">val</span> || (<span class="variable">val</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; !<span class="this">this</span>.<span class="variable">negate</span>)) {
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">attr</span>.<span class="variable">length</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">attr</span>));
}
<span class="keyword">if</span> (<span class="variable">val</span>) {
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">val</span> == <span class="variable">attr</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">' with '</span> + <span class="variable">i</span>(<span class="variable">val</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">attr</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">' with '</span> + <span class="variable">i</span>(<span class="variable">val</span>));
}
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert presence of the given class <code>name</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="keyword">class</span> = <span class="keyword">function</span>(<span class="variable">name</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>;
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">elem</span>.<span class="variable">hasClass</span>(<span class="variable">name</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have class '</span> + <span class="variable">i</span>(<span class="variable">name</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'class'</span>))
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have class '</span> + <span class="variable">i</span>(<span class="variable">name</span>));
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert that header <code>field</code> has the given <code>val</code>. </p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> field</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">field</span>, <span class="variable">val</span>){
<span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="string">'headers'</span>);
<span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">headers</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="variable">field</span>.<span class="variable">toLowerCase</span>(), <span class="variable">val</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert <code>.statusCode</code> of <code>code</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">status</span> = <span class="keyword">function</span>(<span class="variable">code</span>){
<span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="string">'statusCode'</span>);
<span class="keyword">var</span> <span class="variable">status</span> = <span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">statusCode</span>;
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">code</span> == <span class="variable">status</span>
, <span class="string">'expected response code of '</span> + <span class="variable">code</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">code</span>])
+ <span class="string">', but got '</span> + <span class="variable">status</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">status</span>])
, <span class="string">'expected to not respond with '</span> + <span class="variable">code</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">code</span>]));
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert id attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">id</span> = <span class="variable">attr</span>(<span class="string">'id'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert title attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">title</span> = <span class="variable">attr</span>(<span class="string">'title'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert alt attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">alt</span> = <span class="variable">attr</span>(<span class="string">'alt'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert href attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">href</span> = <span class="variable">attr</span>(<span class="string">'href'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert src attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">src</span> = <span class="variable">attr</span>(<span class="string">'src'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert rel attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">rel</span> = <span class="variable">attr</span>(<span class="string">'rel'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert media attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">media</span> = <span class="variable">attr</span>(<span class="string">'media'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert name attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">name</span> = <span class="variable">attr</span>(<span class="string">'name'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert action attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">action</span> = <span class="variable">attr</span>(<span class="string">'action'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert method attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">method</span> = <span class="variable">attr</span>(<span class="string">'method'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert value attribute.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">value</span> = <span class="variable">attr</span>(<span class="string">'value'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert enabled.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'enabled'</span>, <span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">disabled</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'disabled'</span>);
<span class="this">this</span>.<span class="variable">assert</span>(
!<span class="variable">disabled</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be enabled'</span>
, <span class="string">'&lt;not implemented, use .disabled&gt;'</span>);
<span class="keyword">return</span> <span class="this">this</span>;
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert disabled.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'disabled'</span>, <span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">disabled</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'disabled'</span>);
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">disabled</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be disabled'</span>
, <span class="string">'&lt;not implemented, use .enabled&gt;'</span>);
<span class="keyword">return</span> <span class="this">this</span>;
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert checked.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'checked'</span>, <span class="variable">bool</span>(<span class="string">'checked'</span>));</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assert selected.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'selected'</span>, <span class="variable">bool</span>(<span class="string">'selected'</span>));</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Generate a boolean assertion function for the given attr <code>name</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Function</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="variable">bool</span>(<span class="variable">name</span>) {
<span class="keyword">return</span> <span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>;
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">name</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be '</span> + <span class="variable">name</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not be '</span> + <span class="variable">name</span>);
<span class="keyword">return</span> <span class="this">this</span>;
}
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Generate an attr assertion function for the given attr <code>name</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Function</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="variable">attr</span>(<span class="variable">name</span>) {
<span class="keyword">return</span> <span class="keyword">function</span>(<span class="variable">expected</span>){
<span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
, <span class="variable">val</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">name</span>);
<span class="this">this</span>.<span class="variable">assert</span>(
<span class="variable">expected</span> == <span class="variable">val</span>
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have '</span> + <span class="variable">name</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">expected</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">val</span>)
, <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have '</span> + <span class="variable">name</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">expected</span>));
<span class="keyword">return</span> <span class="this">this</span>;
}
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/browser.js"><a href="#">browser</a></h2></td><td>lib/browser.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">EventEmitter</span> = <span class="variable">require</span>(<span class="string">'events'</span>).<span class="class">EventEmitter</span>
, <span class="class">Cookie</span> = <span class="variable">require</span>(<span class="string">'./cookie'</span>)
, <span class="class">CookieJar</span> = <span class="variable">require</span>(<span class="string">'./cookie/jar'</span>)
, <span class="variable">jsdom</span> = <span class="variable">require</span>(<span class="string">'jsdom'</span>)
, <span class="variable">jQuery</span> = <span class="variable">require</span>(<span class="string">'../support/jquery'</span>)
, <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Starting portno.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">port</span> = <span class="number integer">8888</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>Browser</code> with the given <code>html</code> or <code>server</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String | http.Server</em> html</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Browser</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Browser</span>(<span class="variable">html</span>) {
<span class="this">this</span>.<span class="variable">history</span> = [];
<span class="this">this</span>.<span class="variable">cookieJar</span> = <span class="keyword">new</span> <span class="class">CookieJar</span>;
<span class="keyword">if</span> (<span class="string">'string'</span> == <span class="keyword">typeof</span> <span class="variable">html</span>) {
<span class="this">this</span>.<span class="variable">parse</span>(<span class="variable">html</span>);
} <span class="keyword">else</span> {
<span class="this">this</span>.<span class="variable">server</span> = <span class="variable">html</span>;
<span class="this">this</span>.<span class="variable">server</span>.<span class="variable">pending</span> = <span class="number integer">0</span>;
<span class="this">this</span>.<span class="variable">server</span>.<span class="variable">port</span> = <span class="number integer">8888</span>;
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Inherit from <code>EventEmitter.prototype</code>.
</p>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">__proto__</span> = <span class="class">EventEmitter</span>.<span class="variable">prototype</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Parse the given <code>html</code> and populate:</p>
<ul><li><code>.source</code></li><li><code>.window</code></li><li><code>.jQuery</code></li></ul>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> html</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">parse</span> = <span class="keyword">function</span>(<span class="variable">html</span>){
<span class="this">this</span>.<span class="variable">source</span> = <span class="variable">html</span>;
<span class="this">this</span>.<span class="variable">window</span> = <span class="variable">jsdom</span>.<span class="variable">jsdom</span>(<span class="variable">wrap</span>(<span class="variable">html</span>)).<span class="variable">createWindow</span>();
<span class="this">this</span>.<span class="variable">jQuery</span> = <span class="variable">jQuery</span>.<span class="variable">create</span>(<span class="this">this</span>.<span class="variable">window</span>);
<span class="this">this</span>.<span class="variable">jQuery</span>.<span class="variable">browser</span> = <span class="this">this</span>.<span class="variable">jQuery</span>.<span class="variable">fn</span>.<span class="variable">browser</span> = <span class="this">this</span>;
<span class="variable">require</span>(<span class="string">'./jquery'</span>)(<span class="this">this</span>, <span class="this">this</span>.<span class="variable">jQuery</span>);
<span class="this">this</span>.<span class="variable">context</span> = <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="string">'*'</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Set the jQuery context for the duration of <code>fn()</code> to <code>selector</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">within</span> =
<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">context</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">fn</span>){
<span class="keyword">var</span> <span class="variable">prev</span> = <span class="this">this</span>.<span class="variable">context</span>;
<span class="this">this</span>.<span class="variable">context</span> = <span class="this">this</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>);
<span class="variable">fn</span>();
<span class="this">this</span>.<span class="variable">context</span> = <span class="variable">prev</span>;
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Request <code>path</code> with <code>method</code> and callback <code>fn(jQuery)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>String</em> method</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">request</span> = <span class="keyword">function</span>(<span class="variable">method</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
<span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>
, <span class="variable">server</span> = <span class="this">this</span>.<span class="variable">server</span>
, <span class="variable">host</span> = <span class="string">'127.0.0.1'</span>
, <span class="variable">headers</span> = <span class="variable">options</span>.<span class="variable">headers</span> || {};
<span class="comment">// Ensure server</span>
<span class="keyword">if</span> (!<span class="variable">server</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'no .server present'</span>);
++<span class="variable">server</span>.<span class="variable">pending</span>;
<span class="comment">// HTTP client</span>
<span class="comment">// TODO: options for headers, request body etc</span>
<span class="keyword">if</span> (!<span class="variable">server</span>.<span class="variable">fd</span>) {
<span class="variable">server</span>.<span class="variable">listen</span>(++<span class="variable">port</span>, <span class="variable">host</span>);
<span class="variable">server</span>.<span class="variable">client</span> = <span class="variable">http</span>.<span class="variable">createClient</span>(<span class="variable">port</span>);
}
<span class="comment">// Save history</span>
<span class="keyword">if</span> (<span class="variable">false</span> !== <span class="variable">saveHistory</span>) <span class="this">this</span>.<span class="variable">history</span>.<span class="variable">push</span>(<span class="variable">path</span>);
<span class="comment">// Cookies</span>
<span class="keyword">var</span> <span class="variable">cookies</span> = <span class="this">this</span>.<span class="variable">cookieJar</span>.<span class="variable">get</span>({ <span class="variable">url</span>: <span class="variable">path</span> });
<span class="keyword">if</span> (<span class="variable">cookies</span>.<span class="variable">length</span>) {
<span class="variable">headers</span>.<span class="class">Cookie</span> = <span class="variable">cookies</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">cookie</span>){
<span class="keyword">return</span> <span class="variable">cookie</span>.<span class="variable">name</span> + <span class="string">'='</span> + <span class="variable">cookie</span>.<span class="variable">value</span>;
}).<span class="variable">join</span>(<span class="string">'; '</span>);
}
<span class="comment">// Request</span>
<span class="variable">headers</span>.<span class="class">Host</span> = <span class="variable">host</span>;
<span class="keyword">var</span> <span class="variable">req</span> = <span class="variable">server</span>.<span class="variable">client</span>.<span class="variable">request</span>(<span class="variable">method</span>, <span class="variable">path</span>, <span class="variable">headers</span>);
<span class="variable">req</span>.<span class="variable">on</span>(<span class="string">'response'</span>, <span class="keyword">function</span>(<span class="variable">res</span>){
<span class="keyword">var</span> <span class="variable">status</span> = <span class="variable">res</span>.<span class="variable">statusCode</span>
, <span class="variable">buf</span> = <span class="string">''</span>;
<span class="comment">// Cookies</span>
<span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'set-cookie'</span>]) {
<span class="variable">self</span>.<span class="variable">cookieJar</span>.<span class="variable">add</span>(<span class="keyword">new</span> <span class="class">Cookie</span>(<span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'set-cookie'</span>]));
}
<span class="comment">// Success</span>
<span class="keyword">if</span> (<span class="variable">status</span> &<span class="variable">gt</span>;= <span class="number integer">200</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">status</span> &<span class="variable">lt</span>; <span class="number integer">300</span>) {
<span class="keyword">var</span> <span class="variable">contentType</span> = <span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'content-type'</span>];
<span class="comment">// JSON support</span>
<span class="keyword">if</span> (~<span class="variable">contentType</span>.<span class="variable">indexOf</span>(<span class="string">'json'</span>)) {
<span class="variable">res</span>.<span class="variable">body</span> = <span class="string">''</span>;
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">res</span>.<span class="variable">body</span> += <span class="variable">chunk</span>; });
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
<span class="keyword">try</span> {
<span class="variable">res</span>.<span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">parse</span>(<span class="variable">res</span>.<span class="variable">body</span>);
<span class="variable">fn</span>(<span class="variable">res</span>);
} <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'error'</span>, <span class="variable">err</span>);
}
});
<span class="keyword">return</span>;
}
<span class="comment">// Ensure html</span>
<span class="keyword">if</span> (!~<span class="variable">contentType</span>.<span class="variable">indexOf</span>(<span class="string">'text/html'</span>)) {
<span class="keyword">return</span> <span class="variable">fn</span>(<span class="variable">res</span>);
}
<span class="comment">// Buffer html</span>
<span class="variable">res</span>.<span class="variable">setEncoding</span>(<span class="string">'utf8'</span>);
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">buf</span> += <span class="variable">chunk</span>; });
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
<span class="variable">self</span>.<span class="variable">parse</span>(<span class="variable">buf</span>);
<span class="variable">fn</span>(<span class="variable">res</span>, <span class="keyword">function</span>(<span class="variable">selector</span>){
<span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>);
});
});
<span class="comment">// Redirect</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">status</span> &<span class="variable">gt</span>;= <span class="number integer">300</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">status</span> &<span class="variable">lt</span>; <span class="number integer">400</span>) {
<span class="keyword">var</span> <span class="variable">location</span> = <span class="variable">res</span>.<span class="variable">headers</span>.<span class="variable">location</span>;
<span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'redirect'</span>, <span class="variable">location</span>);
<span class="variable">self</span>.<span class="variable">request</span>(<span class="string">'GET'</span>, <span class="variable">location</span>, <span class="variable">options</span>, <span class="variable">fn</span>);
<span class="comment">// Error</span>
} <span class="keyword">else</span> {
<span class="keyword">var</span> <span class="variable">err</span> = <span class="keyword">new</span> <span class="class">Error</span>(
<span class="variable">method</span> + <span class="string">' '</span> + <span class="variable">path</span>
+ <span class="string">' responded with '</span>
+ <span class="variable">status</span> + <span class="string">' &quot;'</span> + <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span>] + <span class="string">'&quot;'</span>);
<span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'error'</span>, <span class="variable">err</span>);
}
});
<span class="variable">req</span>.<span class="variable">end</span>(<span class="variable">options</span>.<span class="variable">body</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>GET <code>path</code> and callback <code>fn(jQuery)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>Object | Function</em> options or fn</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">get</span> =
<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">visit</span> =
<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">open</span> = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
<span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">options</span>) {
<span class="variable">saveHistory</span> = <span class="variable">fn</span>;
<span class="variable">fn</span> = <span class="variable">options</span>;
<span class="variable">options</span> = {};
}
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">request</span>(<span class="string">'GET'</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>POST <code>path</code> and callback <code>fn(jQuery)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>Object | Function</em> options or fn</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">post</span> = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
<span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">options</span>) {
<span class="variable">saveHistory</span> = <span class="variable">fn</span>;
<span class="variable">fn</span> = <span class="variable">options</span>;
<span class="variable">options</span> = {};
}
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">request</span>(<span class="string">'POST'</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>GET the last page visited, or the nth previous page.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">back</span> = <span class="keyword">function</span>(<span class="variable">n</span>, <span class="variable">fn</span>){
<span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">n</span>) <span class="variable">fn</span> = <span class="variable">n</span>, <span class="variable">n</span> = <span class="number integer">1</span>;
<span class="keyword">while</span> (<span class="variable">n</span>--) <span class="this">this</span>.<span class="variable">history</span>.<span class="variable">pop</span>();
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">get</span>(<span class="this">this</span>.<span class="variable">path</span>, <span class="variable">fn</span>, <span class="variable">false</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Locate elements via the given <code>selector</code> and <code>locator</code> supporting:</p>
<ul><li>element text</li><li>element name attribute</li><li>css selector</li></ul>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>jQuery</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">locate</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">locator</span>){
<span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>
, $ = <span class="this">this</span>.<span class="variable">jQuery</span>;
<span class="keyword">var</span> <span class="variable">elems</span> = <span class="this">this</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>).<span class="variable">filter</span>(<span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">elem</span> = $(<span class="this">this</span>);
<span class="keyword">return</span> <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">text</span>()
|| <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'id'</span>)
|| <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'value'</span>)
|| <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'name'</span>)
|| <span class="variable">elem</span>.<span class="variable">is</span>(<span class="variable">locator</span>);
});
<span class="keyword">if</span> (<span class="variable">elems</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; !<span class="variable">elems</span>.<span class="variable">length</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'failed to locate &quot;'</span> + <span class="variable">locator</span> + <span class="string">'&quot; in context of selector &quot;'</span> + <span class="variable">selector</span> + <span class="string">'&quot;'</span>);
<span class="keyword">return</span> <span class="variable">elems</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the current path.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'path'</span>, <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">history</span>[<span class="this">this</span>.<span class="variable">history</span>.<span class="variable">length</span> - <span class="number integer">1</span>];
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Click the given <code>locator</code> and callback <code>fn(res)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">click</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fn</span>){
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':submit, :button, a'</span>, <span class="variable">locator</span>)).<span class="variable">click</span>(<span class="variable">fn</span>, <span class="variable">locator</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assign <code>val</code> to the given <code>locator</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">type</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">val</span>){
<span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'input, textarea'</span>, <span class="variable">locator</span>)).<span class="variable">val</span>(<span class="variable">val</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Uncheck the checkbox with the given <code>locator</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">uncheck</span> = <span class="keyword">function</span>(<span class="variable">locator</span>){
<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':checkbox'</span>, <span class="variable">locator</span>)[<span class="number integer">0</span>].<span class="variable">removeAttribute</span>(<span class="string">'checked'</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check the checkbox with the given <code>locator</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">check</span> = <span class="keyword">function</span>(<span class="variable">locator</span>){
<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':checkbox'</span>, <span class="variable">locator</span>)[<span class="number integer">0</span>].<span class="variable">setAttribute</span>(<span class="string">'checked'</span>, <span class="string">'checked'</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Select <code>options</code> at <code>locator</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>String | Array</em> select</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">select</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">options</span>){
<span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'select'</span>, <span class="variable">locator</span>)).<span class="variable">select</span>(<span class="variable">options</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Submit form at the optional <code>locator</code> and callback <code>fn(res)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String | Function</em> locator</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">submit</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fn</span>){
<span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">locator</span>) {
<span class="variable">fn</span> = <span class="variable">locator</span>;
<span class="variable">locator</span> = <span class="string">'*'</span>;
}
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'form'</span>, <span class="variable">locator</span>)).<span class="variable">submit</span>(<span class="variable">fn</span>, <span class="variable">locator</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Fill the given form <code>fields</code> and optional <code>locator</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>Object</em> fields</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">fill</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fields</span>){
<span class="keyword">if</span> (<span class="string">'object'</span> == <span class="keyword">typeof</span> <span class="variable">locator</span>) {
<span class="variable">fields</span> = <span class="variable">locator</span>;
<span class="variable">locator</span> = <span class="string">'*'</span>;
}
<span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'form'</span>, <span class="variable">locator</span>)).<span class="variable">fill</span>(<span class="variable">fields</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Ensure <code>html</code> / <code>body</code> tags exist.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="variable">wrap</span>(<span class="variable">html</span>) {
<span class="comment">// body</span>
<span class="keyword">if</span> (!~<span class="variable">html</span>.<span class="variable">indexOf</span>(<span class="string">'&lt;body'</span>)) {
<span class="variable">html</span> = <span class="string">'&lt;body&gt;'</span> + <span class="variable">html</span> + <span class="string">'&lt;/body&gt;'</span>;
}
<span class="comment">// html</span>
<span class="keyword">if</span> (!~<span class="variable">html</span>.<span class="variable">indexOf</span>(<span class="string">'&lt;html'</span>)) {
<span class="variable">html</span> = <span class="string">'&lt;html&gt;'</span> + <span class="variable">html</span> + <span class="string">'&lt;/html&gt;'</span>;
}
<span class="keyword">return</span> <span class="variable">html</span>;
}</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/cookie/index.js"><a href="#">index</a></h2></td><td>lib/cookie/index.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>Cookie</code> with the given cookie <code>str</code> and <code>req</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>IncomingRequest</em> req</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Cookie</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Cookie</span>(<span class="variable">str</span>, <span class="variable">req</span>) {
<span class="this">this</span>.<span class="variable">str</span> = <span class="variable">str</span>;
<span class="comment">// First key is the name</span>
<span class="this">this</span>.<span class="variable">name</span> = <span class="variable">str</span>.<span class="variable">substr</span>(<span class="number integer">0</span>, <span class="variable">str</span>.<span class="variable">indexOf</span>(<span class="string">'='</span>));
<span class="comment">// Map the key/val pairs</span>
<span class="variable">str</span>.<span class="variable">split</span>(<span class="regexp">/ *; */</span>).<span class="variable">reduce</span>(<span class="keyword">function</span>(<span class="variable">obj</span>, <span class="variable">pair</span>){
<span class="variable">pair</span> = <span class="variable">pair</span>.<span class="variable">split</span>(<span class="regexp">/ *= */</span>);
<span class="variable">obj</span>[<span class="variable">pair</span>[<span class="number integer">0</span>]] = <span class="variable">pair</span>[<span class="number integer">1</span>] || <span class="variable">true</span>;
<span class="keyword">return</span> <span class="variable">obj</span>;
}, <span class="this">this</span>);
<span class="comment">// Assign value</span>
<span class="this">this</span>.<span class="variable">value</span> = <span class="this">this</span>[<span class="this">this</span>.<span class="variable">name</span>];
<span class="comment">// Expires</span>
<span class="this">this</span>.<span class="variable">expires</span> = <span class="this">this</span>.<span class="variable">expires</span>
? <span class="keyword">new</span> <span class="class">Date</span>(<span class="this">this</span>.<span class="variable">expires</span>)
: <span class="class">Infinity</span>;
<span class="comment">// Default or trim path</span>
<span class="this">this</span>.<span class="variable">path</span> = <span class="this">this</span>.<span class="variable">path</span>
? <span class="this">this</span>.<span class="variable">path</span>.<span class="variable">trim</span>()
: <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">pathname</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the original cookie string.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Cookie</span>.<span class="variable">prototype</span>.<span class="variable">toString</span> = <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">str</span>;
};
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/cookie/jar.js"><a href="#">jar</a></h2></td><td>lib/cookie/jar.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>CookieJar</code>.</p>
<ul><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">CookieJar</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">CookieJar</span>() {
<span class="this">this</span>.<span class="variable">cookies</span> = [];
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add the given <code>cookie</code> to the jar.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Cookie</em> cookie</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">CookieJar</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span>(<span class="variable">cookie</span>){
<span class="this">this</span>.<span class="variable">cookies</span>.<span class="variable">push</span>(<span class="variable">cookie</span>);
};
<span class="class">CookieJar</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span>(<span class="variable">req</span>){
<span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">pathname</span>
, <span class="variable">now</span> = <span class="keyword">new</span> <span class="class">Date</span>;
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">cookies</span>.<span class="variable">filter</span>(<span class="keyword">function</span>(<span class="variable">cookie</span>){
<span class="keyword">return</span> <span class="number integer">0</span> == <span class="variable">path</span>.<span class="variable">indexOf</span>(<span class="variable">cookie</span>.<span class="variable">path</span>)
&<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">now</span> &<span class="variable">lt</span>; <span class="variable">cookie</span>.<span class="variable">expires</span>;
});
};
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/jquery/fill.js"><a href="#">fill</a></h2></td><td>lib/jquery/fill.js</td></tr><tr class="code">
<td class="docs">
<p>Select options.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">select</span> = <span class="keyword">function</span>($, <span class="variable">elems</span>, <span class="variable">val</span>){
<span class="variable">elems</span>.<span class="variable">select</span>(<span class="variable">val</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Fill inputs:</p>
<ul><li>toggle radio buttons</li><li>check checkboxes</li><li><p>default to .val(val)</p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">input</span> = <span class="keyword">function</span>($, <span class="variable">elems</span>, <span class="variable">val</span>){
<span class="keyword">switch</span> (<span class="variable">elems</span>.<span class="variable">attr</span>(<span class="string">'type'</span>)) {
<span class="keyword">case</span> <span class="string">'radio'</span>:
<span class="variable">elems</span>.<span class="variable">each</span>(<span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">elem</span> = $(<span class="this">this</span>);
<span class="variable">val</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'value'</span>)
? <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'checked'</span>, <span class="variable">true</span>)
: <span class="variable">elem</span>.<span class="variable">removeAttr</span>(<span class="string">'checked'</span>);
});
<span class="keyword">break</span>;
<span class="keyword">case</span> <span class="string">'checkbox'</span>:
<span class="variable">val</span>
? <span class="variable">elems</span>.<span class="variable">attr</span>(<span class="string">'checked'</span>, <span class="variable">true</span>)
: <span class="variable">elems</span>.<span class="variable">removeAttr</span>(<span class="string">'checked'</span>);
<span class="keyword">break</span>;
<span class="keyword">default</span>:
<span class="variable">elems</span>.<span class="variable">val</span>(<span class="variable">val</span>);
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Fill textarea.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">textarea</span> = <span class="keyword">function</span>($, <span class="variable">elems</span>, <span class="variable">val</span>){
<span class="variable">elems</span>.<span class="variable">val</span>(<span class="variable">val</span>);
}</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/jquery/index.js"><a href="#">index</a></h2></td><td>lib/jquery/index.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">parse</span> = <span class="variable">require</span>(<span class="string">'url'</span>).<span class="variable">parse</span>
, <span class="variable">fill</span> = <span class="variable">require</span>(<span class="string">'./fill'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Augment the given <code>jQuery</code> instance.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Browser</em> browser</p></li><li><p><strong>param</strong>: <em>jQuery</em> $</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span>(<span class="variable">browser</span>, $){</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Select the given <code>options</code> by text or value attr.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Array</em> options</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>$.<span class="variable">fn</span>.<span class="variable">select</span> = <span class="keyword">function</span>(<span class="variable">options</span>){
<span class="keyword">if</span> (<span class="string">'string'</span> == <span class="keyword">typeof</span> <span class="variable">options</span>) <span class="variable">options</span> = [<span class="variable">options</span>];
<span class="this">this</span>.<span class="variable">find</span>(<span class="string">'option'</span>).<span class="variable">filter</span>(<span class="keyword">function</span>(<span class="variable">i</span>, <span class="variable">option</span>){
<span class="comment">// via text or value</span>
<span class="keyword">var</span> <span class="variable">selected</span> = ~<span class="variable">options</span>.<span class="variable">indexOf</span>($(<span class="variable">option</span>).<span class="variable">text</span>())
|| ~<span class="variable">options</span>.<span class="variable">indexOf</span>(<span class="variable">option</span>.<span class="variable">getAttribute</span>(<span class="string">'value'</span>));
<span class="keyword">if</span> (<span class="variable">selected</span>) {
<span class="variable">option</span>.<span class="variable">setAttribute</span>(<span class="string">'selected'</span>, <span class="string">'selected'</span>);
} <span class="keyword">else</span> {
<span class="variable">option</span>.<span class="variable">removeAttribute</span>(<span class="string">'selected'</span>);
}
})
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Click the first element with callback <code>fn(jQuery, res)</code>
when text/html or <code>fn(res)</code> otherwise.</p>
<ul><li>requests a tag href</li><li>requests form submit's parent form action</li></ul>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>$.<span class="variable">fn</span>.<span class="variable">click</span> = <span class="keyword">function</span>(<span class="variable">fn</span>, <span class="variable">locator</span>){
<span class="keyword">var</span> <span class="variable">url</span>
, <span class="variable">prop</span> = <span class="string">'element'</span>
, <span class="variable">method</span> = <span class="string">'get'</span>
, <span class="variable">locator</span> = <span class="variable">locator</span> || <span class="this">this</span>.<span class="variable">selector</span>
, <span class="variable">options</span> = {};
<span class="keyword">switch</span> (<span class="this">this</span>[<span class="number integer">0</span>].<span class="variable">nodeName</span>) {
<span class="keyword">case</span> <span class="string">'A'</span>:
<span class="variable">prop</span> = <span class="string">'href'</span>;
<span class="variable">url</span> = <span class="this">this</span>.<span class="variable">attr</span>(<span class="string">'href'</span>);
<span class="keyword">break</span>;
<span class="keyword">case</span> <span class="string">'INPUT'</span>:
<span class="keyword">if</span> (<span class="string">'submit'</span> == <span class="this">this</span>.<span class="variable">attr</span>(<span class="string">'type'</span>)) {
<span class="keyword">var</span> <span class="variable">form</span> = <span class="this">this</span>.<span class="variable">parent</span>(<span class="string">'form'</span>).<span class="variable">first</span>();
<span class="variable">method</span> = <span class="variable">form</span>.<span class="variable">attr</span>(<span class="string">'method'</span>) || <span class="string">'get'</span>;
<span class="variable">url</span> = <span class="variable">form</span>.<span class="variable">attr</span>(<span class="string">'action'</span>) || <span class="variable">parse</span>($.<span class="variable">browser</span>.<span class="variable">path</span>).<span class="variable">pathname</span>;
<span class="keyword">if</span> (<span class="string">'get'</span> == <span class="variable">method</span>) {
<span class="variable">url</span> += <span class="string">'?'</span> + <span class="variable">form</span>.<span class="variable">serialize</span>();
} <span class="keyword">else</span> {
<span class="variable">options</span>.<span class="variable">body</span> = <span class="variable">form</span>.<span class="variable">serialize</span>();
<span class="variable">options</span>.<span class="variable">headers</span> = {
<span class="string">'Content-Type'</span>: <span class="string">'application/x-www-form-urlencoded'</span>
};
}
}
<span class="keyword">break</span>;
}
<span class="comment">// Ensure url present</span>
<span class="keyword">if</span> (!<span class="variable">url</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'failed to click '</span> + <span class="variable">locator</span> + <span class="string">', '</span> + <span class="variable">prop</span> + <span class="string">' not present'</span>);
<span class="comment">// Perform request</span>
<span class="variable">browser</span>[<span class="variable">method</span>](<span class="variable">url</span>, <span class="variable">options</span>, <span class="variable">fn</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Apply fill rules to the given <code>fields</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Object</em> fields</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>$.<span class="variable">fn</span>.<span class="variable">fill</span> = <span class="keyword">function</span>(<span class="variable">fields</span>){
<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">locator</span> <span class="keyword">in</span> <span class="variable">fields</span>) {
<span class="keyword">var</span> <span class="variable">val</span> = <span class="variable">fields</span>[<span class="variable">locator</span>]
, <span class="variable">elems</span> = <span class="variable">browser</span>.<span class="variable">locate</span>(<span class="string">'select, input, textarea'</span>, <span class="variable">locator</span>)
, <span class="variable">name</span> = <span class="variable">elems</span>[<span class="number integer">0</span>].<span class="variable">nodeName</span>.<span class="variable">toLowerCase</span>();
<span class="variable">fill</span>[<span class="variable">name</span>]($, <span class="variable">elems</span>, <span class="variable">val</span>);
}
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Submit this form with the given callback fn.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>$.<span class="variable">fn</span>.<span class="variable">submit</span> = <span class="keyword">function</span>(<span class="variable">fn</span>, <span class="variable">locator</span>){
<span class="keyword">var</span> <span class="variable">submit</span> = <span class="this">this</span>.<span class="variable">find</span>(<span class="string">':submit'</span>);
<span class="keyword">if</span> (<span class="variable">submit</span>.<span class="variable">length</span>) {
<span class="variable">submit</span>.<span class="variable">click</span>(<span class="variable">fn</span>, <span class="variable">locator</span>);
} <span class="keyword">else</span> {
$(<span class="string">'&lt;input id=&quot;tobi-submit&quot; type=&quot;submit&quot; /&gt;'</span>)
.<span class="variable">appendTo</span>(<span class="this">this</span>)
.<span class="variable">click</span>(<span class="variable">fn</span>, <span class="variable">locator</span>)
.<span class="variable">remove</span>();
}
};
};</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/tobi.js"><a href="#">tobi</a></h2></td><td>lib/tobi.js</td></tr><tr class="code">
<td class="docs">
<p>Library version.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.0.1'</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Expose <code>Browser</code>.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="class">Browser</span> = <span class="variable">require</span>(<span class="string">'./browser'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Expose <code>Cookie</code>.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="class">Cookie</span> = <span class="variable">require</span>(<span class="string">'./cookie'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Expose <code>CookieJar</code>.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="class">CookieJar</span> = <span class="variable">require</span>(<span class="string">'./cookie/jar'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>Browser</code>.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">createBrowser</span> = <span class="keyword">function</span>(<span class="variable">str</span>){
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">exports</span>.<span class="class">Browser</span>(<span class="variable">str</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Automated should.js support.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">try</span> {
<span class="variable">require</span>(<span class="string">'should'</span>);
<span class="variable">require</span>(<span class="string">'./assertions/should'</span>);
} <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="comment">// Ignore</span>
}</code></pre>
</td>
</tr> </body>
</html></tbody></table>
Jump to Line
Something went wrong with that request. Please try again.