Coverage

18%
317
59
258

/home/ubuntu/src/github.com/dalekjs/dalek-internal-assertions/index.js

18%
317
59
258
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
241'use strict';
25
26// ext. libs
271var Q = require('q');
281var uuid = require('node-uuid');
291var chai = require('chai');
30
31// Module variable
321var Assertions;
33
34/**
35 * @module Assertions
36 * @namespace Dalek.Internal
37 */
38
391module.exports = function () {
401 return Assertions;
41};
42
43/**
44 * Assertions check if the assumptions you made about a website are correct.
45 * For example they might check if the title of a page or the content text of
46 * an element is as expected, or if your mobile website version only displays
47 * a certain amount of elements.
48 *
49 * @class Assertions
50 * @constructor
51 * @part Assertions
52 * @api
53 */
54
551Assertions = function (opts) {
560 this.test = opts.test;
570 this.proceeded = [];
580 this.chaining = false;
59};
60
61/**
62 * It can be really cumbersome to always write assert, assert & assert
63 * all over the place when your doing multiple assertions.
64 * To avoid this, open an assertion context in your test which allows
65 * you to write (n) assertions without having to write 'assert' before each.
66 *
67 * So, instead of writing this:
68 *
69 * ```javascript
70 * test.open('http://doctorwhotv.co.uk/')
71 * .assert.text('#nav').is('Navigation')
72 * .assert.visible('#nav')
73 * .assert.attr('#nav', 'data-nav', 'true')
74 * .done();
75 * ```
76 *
77 * you can write this:
78 *
79 * ```javascript
80 * test.open('http://doctorwhotv.co.uk/')
81 * .assert.chain()
82 * .text('#nav').is('Navigation')
83 * .visible('#nav')
84 * .attr('#nav', 'data-nav', 'true')
85 * .end()
86 * .done();
87 * ```
88 *
89 * to make it even more concise, you can combine this with the [query](actions.html#meth-query) method:
90 *
91 * ```javascript
92 * test.open('http://doctorwhotv.co.uk/')
93 * .assert.chain()
94 * .query('#nav')
95 * .text().is('Navigation')
96 * .visible()
97 * .attr('data-nav', 'true')
98 * .end()
99 * .end()
100 * .done();
101 * ```
102 *
103 * Always make sure, you terminate it with the [end](#meth-end) method!
104 *
105 * @api
106 * @method chain
107 * @chainable
108 */
109
1101Assertions.prototype.chain = function () {
1110 this.test.lastChain.push('chaining');
1120 this.chaining = true;
1130 return this;
114};
115
116/**
117 * Terminates an assertion chain or a query
118 *
119 * ```javascript
120 * test.open('http://doctorwhotv.co.uk/')
121 * .assert.chain()
122 * .query('#nav')
123 * .text().is('Navigation')
124 * .visible()
125 * .attr('data-nav', 'true')
126 * .end()
127 * .end()
128 * .done();
129 * ```
130 *
131 * @api
132 * @method end
133 * @chainable
134 */
135
1361Assertions.prototype.end = function () {
1370 var lastAction = this.test.lastChain.pop();
1380 if (lastAction === 'chaining') {
1390 this.chaining = false;
140 }
141
1420 if (lastAction === 'querying') {
1430 this.test.querying = false;
144 }
1450 return this.test;
146};
147
148/**
149 * Asserts that a given resource does exist in the environment.
150 *
151 * @method resourceExists
152 * @param {string} url URL of the resource to check
153 * @param {string} message Message for the test reporter
154 * @chainable
155 */
156
1571Assertions.prototype.resourceExists = function (url, message) {
1580 var hash = uuid.v4();
1590 var cb = this._generateCallbackAssertion('resourceExists', 'resourceExists', this._testTruthy, hash, {url: url, message: message}).bind(this.test);
1600 this._addToActionQueue([url, hash], 'resourceExists', cb);
1610 return this.chaining ? this : this.test;
162};
163
164/**
165 * Asserts that a given element appears n times on the page.
166 *
167 * Given this portion of HTML, you would like to assure that all of these elements
168 * are ending up in your rendered markup on your page.
169 *
170 * ```html
171 * <section id="blog-overview">
172 * <article class="teaser"></article>
173 * <article class="teaser"></article>
174 * <article class="teaser"></article>
175 * <article class="teaser"></article>
176 * </section>
177 * ```
178 *
179 * The simple solution is to check if all these elements are present
180 *
181 * ```javascript
182 * test.assert.numberOfElements('#blog-overview .teaser', 4, '4 blog teasers are present')
183 * ```
184 * The alternate syntax for this is:
185 *
186 * ```javascript
187 * test.assert.numberOfElements('#blog-overview .teaser')
188 * .is(4, '4 blog teasers are present')
189 * ```
190 *
191 * If you are not sure how many elements will exactly end up in your markup,
192 * you could use the between assertion handler
193 *
194 * ```javascript
195 * test.assert.numberOfElements('#blog-overview .teaser')
196 * .is.between([2, 6], 'Between 2 and 6 blog teasers are present')
197 * ```
198 *
199 * If you dealing with the situation that you have a minimum of elements,
200 * you expect, you can use this helper:
201 *
202 * ```javascript
203 * test.assert.numberOfElements('#blog-overview .teaser')
204 * .is.gt(2, 'At least 3 blog teasers are present')
205 * ```
206 * If you want to know if its 'greater than equal', use this one
207 *
208 * ```javascript
209 * test.assert.numberOfElements('#blog-overview .teaser')
210 * .is.gte(2, 'At least 2 blog teasers are present')
211 * ```
212 * as well as their 'lower than' and 'lower than equal' equivalents.
213 *
214 * ```javascript
215 * test.assert.numberOfElements('#blog-overview .teaser')
216 * .is.lt(5, 'Less than 5 blog teasers are present')
217 * ```
218 *
219 * ```javascript
220 * test.assert.numberOfElements('#blog-overview .teaser')
221 * .is.lte(5, 'Less than, or 5 blog teasers are present')
222 * ```
223 * And if you just want to know, if a certain amount of teasers isnʼt present,
224 * you can still use the not() assertion helper
225 *
226 * ```javascript
227 * test.assert.numberOfElements('#blog-overview .teaser')
228 * .is.not(5, 'There are more or less than 5 teasers present')
229 * ```
230 *
231 * @api
232 * @method numberOfElements
233 * @param {string} selector Selector that matches the elements to test
234 * @param {string} expected Expected test result
235 * @param {string} message Message for the test reporter
236 * @chainable
237 */
238
2391Assertions.prototype.numberOfElements = function (selector, expected, message) {
2400 var hash = uuid.v4();
241
2420 if (this.test.querying === true) {
2430 message = expected;
2440 expected = selector;
2450 selector = this.test.selector;
246 }
247
2480 var cb = this._generateCallbackAssertion('numberOfElements', 'numberOfElements', this._testShallowEquals, hash, {expected: expected, selector: selector, message: message}).bind(this.test);
2490 this._addToActionQueue([selector, expected, hash], 'getNumberOfElements', cb);
2500 return this.chaining ? this : this.test;
251};
252
253/**
254 *
255 * Asserts that a given element is visible n times in the current viewport.
256 *
257 *
258 * Given this portion of HTML, you would like to assure that all of these elements
259 * are ending up in your rendered markup on your page.
260 *
261 * ```html
262 * <section id="blog-overview">
263 * <article class="teaser"></article>
264 * <article class="teaser"></article>
265 * <article class="teaser"></article>
266 * <article class="teaser"></article>
267 * </section>
268 * ```
269 *
270 * The simple solution is to check if all these elements are visible
271 *
272 * ```javascript
273 * test.assert.numberOfVisibleElements('#blog-overview .teaser', 4, '4 blog teasers are visible')
274 * ```
275 * The alternate syntax for this is:
276 *
277 * ```javascript
278 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
279 * .is(4, '4 blog teasers are visible')
280 * ```
281 *
282 * If you are not sure how many elements will exactly be shown in the current viewport,
283 * you could use the between assertion handler
284 *
285 * ```javascript
286 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
287 * .is.between(2, 6, 'Between 2 and 6 blog teasers are visible')
288 * ```
289 *
290 * If you dealing with the situation that you have a minimum of elements,
291 * you expect, use this helper:
292 *
293 * ```javascript
294 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
295 * .is.gt(2, 'At least 3 blog teasers are visible')
296 * ```
297 * If you want to know if its 'greater than equal', you can use this one
298 *
299 * ```javascript
300 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
301 * .is.gte(2, 'At least 2 blog teasers are visible')
302 * ```
303 * as well as their 'lower than' and 'lower than equal' equivalents.
304 *
305 * ```javascript
306 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
307 * .is.lt(5, 'Less than 5 blog teasers are visible')
308 * ```
309 *
310 * ```javascript
311 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
312 * .is.lte(5, 'Less than, or 5 blog teasers are visible')
313 * ```
314 * And if you just want to know, if a certain amount of teasers isnʼt visible,
315 * you can still use the ':not(): assertion helper
316 *
317 * ```javascript
318 * test.assert.numberOfVisibleElements('#blog-overview .teaser')
319 * .is.not(5, 'There are more or less than 5 teasers visible')
320 * ```
321 *
322 * > NOTE: Buggy on all browsers
323 *
324 * @api
325 * @method numberOfVisibleElements
326 * @param {string} selector Selector that matches the elements to test
327 * @param {string} expected Expected test result
328 * @param {string} message Message for the test reporter
329 * @chainable
330 */
331
3321Assertions.prototype.numberOfVisibleElements = function (selector, expected, message) {
3330 var hash = uuid.v4();
334
3350 if (this.test.querying === true) {
3360 message = expected;
3370 expected = selector;
3380 selector = this.test.selector;
339 }
340
3410 var cb = this._generateCallbackAssertion('numberOfVisibleElements', 'numberOfVisibleElements', this._testShallowEquals, hash, {expected: expected, selector: selector, message: message}).bind(this.test);
3420 this._addToActionQueue([selector, expected, hash], 'getNumberOfVisibleElements', cb);
3430 return this.chaining ? this : this.test;
344};
345
346/**
347 * Asserts that a given form field has the provided value.
348 *
349 * Given this portion of HTML, we would like to get the information which option element
350 * is currently selected.
351 *
352 * ```html
353 * <form name="fav-doctor" id="fav-doctor">
354 * <select id="the-doctors">
355 * <option value="9">Eccleston</option>
356 * <option selected value="10">Tennant</option>
357 * <option value="11">Smith</option>
358 * </select>
359 * </form>
360 * ```
361 *
362 * ```javascript
363 * test
364 * .assert.val('#the-doctors', 10, 'David is the favourite')
365 * // lets change the favourite by selection the last option
366 * .click('#the-doctors option:last')
367 * .assert.val('#the-doctors', 11, 'Matt is now my favourite, bow ties are cool')
368 * ```
369 *
370 * This assertion is capable of getting the values from every form element
371 * that holds a value attribute
372 *
373 * Getting texts out of normal input fields is pretty straight forward
374 *
375 * ```html
376 * <label for="fav-enemy">Tell my your favourity Who enemy:</label>
377 * <input id="fav-enemy" name="fav-enemy" type="text" value="Daleks" />
378 * ```
379 *
380 * ```javascript
381 * test
382 * .assert.val('#fav-enemy', 'Daleks', 'Daleks are so cute')
383 * // lets change the favourite by typing smth. new
384 * .type('#fav-enemy', 'Cyberman')
385 * .assert.val('#fav-enemy', 'Cyberman', 'Cyberman are so cyber')
386 * ```
387 *
388 * @api
389 * @method val
390 * @param {string} selector Selector that matches the elements to test
391 * @param {string} expected Expected test result
392 * @param {string} message Message for the test reporter
393 * @chainable
394 */
395
3961Assertions.prototype.val = function (selector, expected, message) {
3970 var hash = uuid.v4();
398
3990 if (this.test.querying === true) {
4000 message = expected;
4010 expected = selector;
4020 selector = this.test.selector;
403 }
404
4050 var cb = this._generateCallbackAssertion('val', 'val', this._testShallowEquals, hash, {expected: expected, selector: selector, message: message}).bind(this.test);
4060 this._addToActionQueue([selector, expected, hash], 'val', cb);
4070 return this.chaining ? this : this.test;
408};
409
410/**
411 * Checks the computed style.
412 *
413 * ```html
414 * <div id="superColoredElement">Rose</div>
415 * ```
416 *
417 * ```css
418 * #superColoredElement {
419 * background-color: rgba(255, 0, 0, 1);
420 * color: rgba(0, 128, 0, 1);
421 * }
422 * ```
423 *
424 * ```javascript
425 * test
426 * .open('http://unicorns.rainbows.io')
427 * .assert.css('#superColoredElement', 'background-color', 'rgba(255, 0, 0, 1)')
428 * .assert.css('#superColoredElement', 'color', 'rgba(0, 128, 0, 1)')
429 * .done();
430 * ```
431 *
432 * @api
433 * @method css
434 * @param {string} selector Selector that matches the elements to test
435 * @param {string} property CSS property to check
436 * @param {string} expected Expected test result
437 * @param {string} message Message for the test reporter
438 * @chainable
439 */
440
4411Assertions.prototype.css = function (selector, property, expected, message) {
4420 var hash = uuid.v4();
443
4440 if (this.test.querying === true) {
4450 message = expected;
4460 expected = property;
4470 property = selector;
4480 selector = this.test.selector;
449 }
450
4510 var cb = this._generateCallbackAssertion('css', 'css', this._testShallowEquals, hash, {expected: expected, selector: selector, porperty: property, message: message}).bind(this.test);
4520 this._addToActionQueue([selector, property, expected, hash], 'css', cb);
4530 return this.chaining ? this : this.test;
454};
455
456/**
457 * Checks the actual width of an element.
458 *
459 * ```html
460 * <div id="fixed-dimensions" style="width: 100px"></div>
461 * ```
462 *
463 * ```javascript
464 * test
465 * .open('http://localhost:5000/index.html')
466 * // all true, all pixel
467 * .assert.width('#fixed-dimensions', 100)
468 * .assert.width('#fixed-dimensions').is(100)
469 * .assert.width('#fixed-dimensions').is.not(100)
470 * .assert.width('#fixed-dimensions').is.gt(90)
471 * .assert.width('#fixed-dimensions').is.gte(97)
472 * .assert.width('#fixed-dimensions').is.lt(120)
473 * .assert.width('#fixed-dimensions').is.lte(110)
474 * .assert.width('#fixed-dimensions').is.between([90, 110])
475 * .done();
476 *
477 * ```
478 *
479 * @api
480 * @method width
481 * @param {string} selector Selector that matches the elements to test
482 * @param {string} expected Expected test result
483 * @param {string} message Message for the test reporter
484 * @chainable
485 */
486
4871Assertions.prototype.width = function (selector, expected, message) {
4880 var hash = uuid.v4();
489
4900 if (this.test.querying === true) {
4910 message = expected;
4920 expected = selector;
4930 selector = this.test.selector;
494 }
495
4960 var cb = this._generateCallbackAssertion('width', 'width', this._testShallowEquals, hash, {expected: expected, selector: selector, message: message}).bind(this.test);
4970 this._addToActionQueue([selector, expected, hash], 'width', cb);
4980 return this.chaining ? this : this.test;
499};
500
501/**
502 * Checks the actual height of an element.
503 *
504 * ```html
505 * <div id="fixed-dimensions" style="height: 100px"></div>
506 * ```
507 *
508 * ```javascript
509 * test
510 * .open('http://localhost:5000/index.html')
511 * // all true, all pixel
512 * .assert.height('#fixed-dimensions', 100)
513 * .assert.height('#fixed-dimensions').is(100)
514 * .assert.height('#fixed-dimensions').is.not(100)
515 * .assert.height('#fixed-dimensions').is.gt(90)
516 * .assert.height('#fixed-dimensions').is.gte(97)
517 * .assert.height('#fixed-dimensions').is.lt(120)
518 * .assert.height('#fixed-dimensions').is.lte(110)
519 * .assert.height('#fixed-dimensions').is.between([90, 110])
520 * .done();
521 *
522 * ```
523 *
524 * @api
525 * @method height
526 * @param {string} selector Selector that matches the elements to test
527 * @param {string} expected Expected test result
528 * @param {string} message Message for the test reporter
529 * @chainable
530 */
531
5321Assertions.prototype.height = function (selector, expected, message) {
5330 var hash = uuid.v4();
534
5350 if (this.test.querying === true) {
5360 message = expected;
5370 expected = selector;
5380 selector = this.test.selector;
539 }
540
5410 var cb = this._generateCallbackAssertion('height', 'height', this._testShallowEquals, hash, {expected: expected, selector: selector, message: message}).bind(this.test);
5420 this._addToActionQueue([selector, expected, hash], 'height', cb);
5430 return this.chaining ? this : this.test;
544};
545
546/**
547 * Determine if an <option> element, or an <input> element of type checkbox or radio is currently selected.
548 *
549 * ```html
550 * <input type="checkbox" id="unchecked_checkbox" name="unchecked_checkbox"/>
551 * <input type="checkbox" id="checked_checkbox" name="checked_checkbox" checked="checked"/>
552 * <select id="select_elm" name="select_elm">
553 * <option value="9">Eccleston</option>
554 * <option selected value="10">Tennant</option>
555 * <option value="11">Smith</option>
556 * </select>
557 * ```
558 *
559 * Checking radio and checkboxes:
560 *
561 * ```javascript
562 * test
563 * .open('http://selectables.org')
564 * .assert.selected('#checked_checkbox')
565 * .done();
566 * ```
567 *
568 * Checking option elements:
569 *
570 * ```javascript
571 * test
572 * .open('http://selectables.org')
573 * .assert.selected('#select_elm option:nth-child(2)')
574 * .done();
575 * ```
576 *
577 * @api
578 * @method selected
579 * @param {string} selector Selector that matches the elements to test
580 * @param {string} message Message for the test reporter
581 * @chainable
582 */
583
5841Assertions.prototype.selected = function (selector, message) {
5850 var hash = uuid.v4();
586
5870 if (this.test.querying === true) {
5880 message = selector;
5890 selector = this.test.selector;
590 }
591
5920 var cb = this._generateCallbackAssertion('selected', 'selected', this._testShallowEquals, hash, {expected: true, selector: selector, message: message}).bind(this.test);
5930 this._addToActionQueue([selector, true, hash], 'selected', cb);
5940 return this.chaining ? this : this.test;
595};
596
597/**
598 * Determine if an <option> element, or an <input> element of type
599 * checkbox or radio is currently not selected.
600 *
601 * ```html
602 * <input type="checkbox" id="unchecked_checkbox" name="unchecked_checkbox"/>
603 * <input type="checkbox" id="checked_checkbox" name="checked_checkbox" checked="checked"/>
604 * <select id="select_elm" name="select_elm">
605 * <option value="9">Eccleston</option>
606 * <option selected value="10">Tennant</option>
607 * <option value="11">Smith</option>
608 * </select>
609 * ```
610 *
611 * Checking radio and checkboxes:
612 *
613 * ```javascript
614 * test
615 * .open('http://selectables.org')
616 * .assert.notSelected('#unchecked_checkbox')
617 * .done();
618 * ```
619 *
620 * Checking option elements:
621 *
622 * ```javascript
623 * test
624 * .open('http://selectables.org')
625 * .assert.notSelected('#select_elm option:last-child')
626 * .done();
627 * ```
628 *
629 * @api
630 * @method notSelected
631 * @param {string} selector Selector that matches the elements to test
632 * @param {string} message Message for the test reporter
633 * @chainable
634 */
635
6361Assertions.prototype.notSelected = function (selector, message) {
6370 var hash = uuid.v4();
638
6390 if (this.test.querying === true) {
6400 message = selector;
6410 selector = this.test.selector;
642 }
643
6440 var cb = this._generateCallbackAssertion('selected', 'selected', this._testShallowEquals, hash, {expected: false, selector: selector, message: message}).bind(this.test);
6450 this._addToActionQueue([selector, false, hash], 'selected', cb);
6460 return this.chaining ? this : this.test;
647};
648
649/**
650 * Determine if an element is currently enabled.
651 *
652 * ```html
653 * <input id="onmars" type="text" size="50" name="onmars" placeholder="State your name, rank and intention!"></input>
654 * ```
655 *
656 * ```javascript
657 * test
658 * .open('http://doctor.thedoctor.com/doctor')
659 * .assert.enabled('#onmars', 'Is enabled!')
660 * .done();
661 * ```
662 *
663 * @api
664 * @method enabled
665 * @param {string} selector Selector that matches the elements to test
666 * @param {string} message Message for the test reporter
667 * @chainable
668 */
669
6701Assertions.prototype.enabled = function (selector, message) {
6710 var hash = uuid.v4();
672
6730 if (this.test.querying === true) {
6740 message = selector;
6750 selector = this.test.selector;
676 }
677
6780 var cb = this._generateCallbackAssertion('enabled', 'enabled', this._testShallowEquals, hash, {expected: true, selector: selector, message: message}).bind(this.test);
6790 this._addToActionQueue([selector, true, hash], 'enabled', cb);
6800 return this.chaining ? this : this.test;
681};
682
683/**
684 * Determine if an element is currently disabled.
685 *
686 * ```html
687 * <input disabled id="onearth" type="text" size="50" name="onearth" placeholder="State your name, rank and intention!"></input>
688 * ```
689 *
690 * ```javascript
691 * test
692 * .open('http://doctor.thedoctor.com/doctor')
693 * .assert.disabled('#onearth', 'Is disabled!')
694 * .done();
695 * ```
696 *
697 * @api
698 * @method disabled
699 * @param {string} selector Selector that matches the elements to test
700 * @param {string} message Message for the test reporter
701 * @chainable
702 */
703
7041Assertions.prototype.disabled = function (selector, message) {
7050 var hash = uuid.v4();
706
7070 if (this.test.querying === true) {
7080 message = selector;
7090 selector = this.test.selector;
710 }
711
7120 var cb = this._generateCallbackAssertion('enabled', 'enabled', this._testShallowEquals, hash, {expected: false, selector: selector, message: message}).bind(this.test);
7130 this._addToActionQueue([selector, false, hash], 'enabled', cb);
7140 return this.chaining ? this : this.test;
715};
716
717/**
718 * Checks the contents of a cookie.
719 *
720 * ```javascript
721 * test
722 * .open('http://cookiejar.io/not_your_mothers_javascript.html')
723 * .setCookie('atestcookie', 'foobar=baz')
724 * .assert.cookie('atestcookie', 'foobar=baz')
725 * .done();
726 * ```
727 *
728 * @api
729 * @method cookie
730 * @param {string} name Name of the cookie
731 * @param {string} expect Expected testresult
732 * @param {string} message Message for the test reporter
733 * @chainable
734 */
735
7361Assertions.prototype.cookie = function (name, expected, message) {
7370 var hash = uuid.v4();
7380 var cb = this._generateCallbackAssertion('cookie', 'cookie', this._testShallowEquals, hash, {expected: expected, name: name, message: message}).bind(this.test);
7390 this._addToActionQueue([name, expected, hash], 'cookie', cb);
7400 return this.chaining ? this : this.test;
741};
742
743/**
744 * Asserts that current HTTP status code is the same as the one passed as argument.
745 * TODO: Needs some work to be implement (maybe JavaScript, Webdriver ha no method for this)
746 *
747 * @method httpStatus
748 * @param {integer} status HTTP status code
749 * @param {string} message Message for the test reporter
750 * @chainable
751 */
752
7531Assertions.prototype.httpStatus = function (status, message) {
7540 var hash = uuid.v4();
7550 var cb = this._generateCallbackAssertion('httpStatus', 'httpStatus', this._testShallowEquals, hash, {expected: status, message: message}).bind(this.test);
7560 this._addToActionQueue([status, hash], 'httpStatus', cb);
7570 return this.chaining ? this : this.test;
758};
759
760/**
761 * Asserts that an element matching the provided selector expression exists in remote DOM environment.
762 *
763 * ```html
764 * <body>
765 * <p id="so-lonely">Last of the timelords</p>
766 * </body>
767 * ```
768 *
769 * ```javascript
770 * test
771 * .open('http://doctor.thedoctor.com/doctor')
772 * .assert.exists('#so-lonely', 'The loneliest element in the universe exists')
773 * .done()
774 * ```
775 *
776 * @api
777 * @method exists
778 * @param {string} selector Selector that matches the elements to test
779 * @param {string} message Message for the test reporter
780 * @chainable
781 */
782
7831Assertions.prototype.exists = function (selector, message) {
7840 var hash = uuid.v4();
785
7860 if (this.test.querying === true) {
7870 message = selector;
7880 selector = this.test.selector;
789 }
790
7910 var cb = this._generateCallbackAssertion('exists', 'exists', this._testTruthy, hash, {selector: selector, message: message}).bind(this.test);
7920 this._addToActionQueue([selector, hash], 'exists', cb);
7930 return this.chaining ? this : this.test;
794};
795
796/**
797 * Asserts that an element matching the provided selector expression doesnʼt
798 * exists within the remote DOM environment.
799 *
800 * ```html
801 * <body>
802 * <p id="so-lonely">Last of the time lords</p>
803 * </body>
804 * ```
805 *
806 * ```javascript
807 * test
808 * .open('http://doctor.thedoctor.com/doctor')
809 * .assert.doesntExist('#the-master', 'The master element has not been seen')
810 * .done();
811 * ```
812 *
813 * @api
814 * @method doesntExist
815 * @param {string} selector Selector that matches the elements to test
816 * @param {string} message Message for the test reporter
817 * @chainable
818 */
819
8201Assertions.prototype.doesntExist = function (selector, message) {
8210 var hash = uuid.v4();
822
8230 if (this.test.querying === true) {
8240 message = selector;
8250 selector = this.test.selector;
826 }
827
8280 var cb = this._generateCallbackAssertion('exists', '!exists', this._testFalsy, hash, {selector: selector, message: message}).bind(this.test);
8290 this._addToActionQueue([selector, hash], 'exists', cb);
8300 return this.chaining ? this : this.test;
831};
832
833/**
834 * Asserts that the element matching the provided selector expression is not visible.
835 *
836 * ```html
837 * <body>
838 * <h1 style="display: none">Me? So hidden …</h1>
839 * <h2>Me? So in viewport...</h2>
840 * </body>
841 * ```
842 *
843 * ```javascript
844 * test
845 * .open('http://allyourviewportsbelongto.us')
846 * .assert.notVisible('h1', 'Element is not visible')
847 * .done();
848 * ```
849 *
850 *
851 * > NOTE: Buggy on all browsers
852 *
853 * @api
854 * @method notVisible
855 * @param {string} selector Selector that matches the elements to test
856 * @param {string} message Message for the test reporter
857 * @chainable
858 */
859
8601Assertions.prototype.notVisible = function (selector, message) {
8610 var hash = uuid.v4();
862
8630 if (this.test.querying === true) {
8640 message = selector;
8650 selector = this.test.selector;
866 }
867
8680 var cb = this._generateCallbackAssertion('visible', '!visible', this._testFalsy, hash, {selector: selector, message: message}).bind(this.test);
8690 this._addToActionQueue([selector, hash], 'visible', cb);
8700 return this.chaining ? this : this.test;
871};
872
873/**
874 * Asserts that the element matching the provided selector expression is visible.
875 *
876 * ```html
877 * <body>
878 * <h1>Me? So in viewport …</h1>
879 * </body>
880 * ```
881 *
882 * ```javascript
883 * test
884 * .open('http://allyourviewportsbelongto.us')
885 * .assert.visible('h1', 'Element is visible')
886 * .done();
887 * ```
888 *
889 * > NOTE: Buggy on all browsers
890 *
891 * @api
892 * @method visible
893 * @param {string} selector Selector that matches the elements to test
894 * @param {string} message Message for the test reporter
895 * @chainable
896 */
897
8981Assertions.prototype.visible = function (selector, message) {
8990 var hash = uuid.v4();
900
9010 if (this.test.querying === true) {
9020 message = selector;
9030 selector = this.test.selector;
904 }
905
9060 var cb = this._generateCallbackAssertion('visible', 'visible', this._testTruthy, hash, {selector: selector, message: message}).bind(this.test);
9070 this._addToActionQueue([selector, hash], 'visible', cb);
9080 return this.chaining ? this : this.test;
909};
910
911/**
912 * Asserts that given text does not exist in the provided selector.
913 *
914 * ```html
915 * <body>
916 * <h1>This is a CasperJS sandbox</h1>
917 * </body>
918 * ```
919 *
920 * ```javascript
921 * test
922 * .open('http://dalekjs.com/guineapig/')
923 * .assert.doesntHaveText('h1', 'This page is a Dalek sandbox', 'It´s a sandbox!')
924 * .done();
925 * ```
926 *
927 * @api
928 * @method doesntHaveText
929 * @param {string} selector Selector that matches the elements to test
930 * @param {string} expected Expected test result
931 * @param {string} message Message for the test reporter
932 * @chainable
933 */
934
9351Assertions.prototype.doesntHaveText = function (selector, expected, message) {
9360 var hash = uuid.v4();
9370 if (this.test.querying === true) {
9380 message = expected;
9390 expected = selector;
9400 selector = this.test.selector;
941 }
942
9430 var cb = this._generateCallbackAssertion('text', '!text', this._testShallowUnequals, hash, {selector: selector, expected: expected, message: message}).bind(this.test);
9440 this._addToActionQueue([selector, expected, hash], 'text', cb);
9450 return this.chaining ? this : this.test;
946};
947
948/**
949 * Asserts that given text does not exist in the current alert/prompt/confirm dialog.
950 *
951 * ```html
952 * <a href="#" id="alert_confirm" onclick="confirm('Confirm me!')">I make confirm</a>
953 * ```
954 *
955 * ```javascript
956 * test
957 * .open('http://skaaro.com/index.html')
958 * .click('#alert_confirm')
959 * .assert.dialogDoesntHaveText('I am an alert')
960 * .accept()
961 * .done();
962 * ```
963 *
964 * > NOTE: Does not work in Firefox & PhantomJS
965 *
966 * @api
967 * @method dialogDoesntHaveText
968 * @param {string} expected Expected test result
969 * @param {string} message Message for the test reporter
970 * @chainable
971 */
972
9731Assertions.prototype.dialogDoesntHaveText = function (expected, message) {
9740 var hash = uuid.v4();
9750 var cb = this._generateCallbackAssertion('alertText', '!alertText', this._testShallowUnequals, hash, {expected: expected, message: message}).bind(this.test);
9760 this._addToActionQueue([expected, hash], 'alertText', cb);
9770 return this.chaining ? this : this.test;
978};
979
980/**
981 * Asserts that given text does exist in the provided selector.
982 *
983 * ```html
984 * <body>
985 * <h1>This is a Dalek sandbox</h1>
986 * </body>
987 * ```
988 *
989 * ```javascript
990 * test
991 * .open('http://dalekjs.com/guineapig/')
992 * .assert.text('h1', 'This page is a Dalek sandbox', 'Exterminate!')
993 * .done();
994 * ```
995 *
996 * of course, text works also with the assertion helpers is() and not()
997 *
998 * ```javascript
999 * test
1000 * .open('http://dalekjs.com/guineapig/')
1001 * .assert.text('h1').is('This page is a Dalek sandbox', 'Exterminate!')
1002 * .done();
1003 * ```
1004 *
1005 * ```javascript
1006 * test
1007 * .open('http://dalekjs.com/guineapig/')
1008 * .assert.text('h1').is.not('This page is a CasperJS sandbox', 'Exterminate!')
1009 * .done();
1010 * ```
1011 *
1012 * @api
1013 * @method text
1014 * @param {string} selector Selector that matches the elements to test
1015 * @param {string} expected Expected test result
1016 * @param {string} message Message for the test reporter
1017 * @chainable
1018 */
1019
10201Assertions.prototype.text = function (selector, expected, message) {
10210 var hash = uuid.v4();
10220 if (this.test.querying === true) {
10230 message = expected;
10240 expected = selector;
10250 selector = this.test.selector;
1026 }
1027
10280 var cb = this._generateCallbackAssertion('text', 'text', this._testShallowEquals, hash, {selector: selector, expected: expected, message: message}).bind(this.test);
10290 this._addToActionQueue([selector, expected, hash], 'text', cb);
10300 return (this.chaining || this.test.querying) ? this : this.test;
1031};
1032
1033/**
1034 * Asserts that given alertText does exist in the provided alert/confirm or prompt dialog.
1035 *
1036 * ```html
1037 * <a href="#" id="alert" onclick="alert('I am an alert')">I make alerts!</a>
1038 * ```
1039 *
1040 * ```javascript
1041 * test
1042 * .open('http://skaaro.com/index.html')
1043 * .click('#alert_confirm')
1044 * .assert.dialogText('I am an alert')
1045 * .accept()
1046 * .done();
1047 * ```
1048 *
1049 * of course, text works also with the assertion helpers is() and not()
1050 *
1051 * ```javascript
1052 * test
1053 * .open('http://dalekjs.com/guineapig/')
1054 * .assert.dialogText().is('I am an alert', 'Exterminate!')
1055 * .done();
1056 * ```
1057 *
1058 * ```javascript
1059 * test
1060 * .open('http://dalekjs.com/guineapig/')
1061 * .assert.dialogText().is.not('I am an prompt', 'Exterminate!')
1062 * .done();
1063 * ```
1064 *
1065 *
1066 * > NOTE: Does not work in Firefox & PhantomJS
1067 *
1068 * @api
1069 * @method dialogText
1070 * @param {string} expected Expected testresult
1071 * @param {string} message Message for the test reporter
1072 * @chainable
1073 */
1074
10751Assertions.prototype.dialogText = function (expected, message) {
10760 var hash = uuid.v4();
10770 var cb = this._generateCallbackAssertion('alertText', 'alertText', this._testShallowEquals, hash, {expected: expected, message: message}).bind(this.test);
10780 this._addToActionQueue([expected, hash], 'alertText', cb);
10790 return (this.chaining || this.test.querying) ? this : this.test;
1080};
1081
1082/**
1083 * Asserts that the page title is as expected.
1084 *
1085 * ```javascript
1086 * test.open('http://doctorwhotv.co.uk/')
1087 * .assert.title('Doctor Who TV', 'Not your Daleks TV')
1088 * .done();
1089 * ```
1090 *
1091 * Yep, using assertion helpers is also possible:
1092 *
1093 * ```javascript
1094 * test.open('http://doctorwhotv.co.uk/')
1095 * .assert.title().is('Doctor Who TV', 'Not your Daleks TV')
1096 * .done();
1097 * ```
1098 *
1099 * and the not() helper is available too:
1100 *
1101 * ```javascript
1102 * test.open('http://doctorwhotv.co.uk/')
1103 * .assert.title().is.not('Dalek Emperor TV', 'Not your Daleks TV')
1104 * .done();
1105 * ```
1106 *
1107 * @api
1108 * @method title
1109 * @param {string} expected Expected test result
1110 * @param {string} message Message for the test reporter
1111 * @chainable
1112 */
1113
11141Assertions.prototype.title = function (expected, message) {
11150 var hash = uuid.v4();
11160 var cb = this._generateCallbackAssertion('title', 'title', this._testShallowEquals, hash, {expected: expected, message: message}).bind(this.test);
11170 this._addToActionQueue([expected, hash], 'title', cb);
11180 return this.chaining ? this : this.test;
1119};
1120
1121/**
1122 * Asserts that given title does not match the given expectations.
1123 *
1124 * ```javascript
1125 * test.open('http://doctorwhotv.co.uk/')
1126 * .assert.doesntHaveTitle('Dalek Emperor TV', 'Not your Daleks TV')
1127 * .done();
1128 * ```
1129 *
1130 * @api
1131 * @method doesntHaveTitle
1132 * @param {string} expected Expected test result
1133 * @param {string} message Message for the test reporter
1134 * @chainable
1135 */
1136
11371Assertions.prototype.doesntHaveTitle = function (expected, message) {
11380 var hash = uuid.v4();
11390 var cb = this._generateCallbackAssertion('title', '!title', this._testShallowUnequals, hash, {expected: expected, message: message}).bind(this.test);
11400 this._addToActionQueue([expected, hash], 'title', cb);
11410 return this.chaining ? this : this.test;
1142};
1143
1144/**
1145 * Asserts that the pages url is as expected.
1146 *
1147 * ```javascript
1148 * test.open('http://doctorwhotv.co.uk/')
1149 * .assert.url('http://doctorwhotv.co.uk/', 'URL is as expected')
1150 * .done();
1151 * ```
1152 *
1153 * You can also check if the protocol changed,
1154 * nice to see when you open GitHub with 'http' instead of 'https'
1155 *
1156 * ```javascript
1157 * test.open('http://github.com')
1158 * .assert.url('https://github.com/', 'Changed prototcols')
1159 * .done();
1160 * ```
1161 *
1162 * Yep, using assertion helpers is also possible:
1163 *
1164 * ```javascript
1165 * test.open('http://github.com')
1166 * .assert.url().is('http://doctorwhotv.co.uk/', 'URL is as expected')
1167 * .done();
1168 * ```
1169 *
1170 * and the not() helper is available too:
1171 *
1172 * ```javascript
1173 * test.open('http://doctorwhotv.co.uk/')
1174 * .assert.url().is.not('http://doctorwhotv.co.uk/', 'URL is as expected')
1175 * .done();
1176 * ```
1177 *
1178 * @api
1179 * @method url
1180 * @param {string} expected Expected test result
1181 * @param {string} message Message for the test reporter
1182 * @chainable
1183 */
1184
11851Assertions.prototype.url = function (expected, message) {
11860 var hash = uuid.v4();
11870 var cb = this._generateCallbackAssertion('url', 'url', this._testShallowEquals, hash, {expected: expected, message: message}).bind(this.test);
11880 this._addToActionQueue([expected, hash], 'url', cb);
11890 return this.chaining ? this : this.test;
1190};
1191
1192/**
1193 * Asserts that the pages URL does not match the expectation.
1194 *
1195 * ```javascript
1196 * test.open('http://doctorwhotv.co.uk/')
1197 * .assert.doesntHaveUrl('http://doctorwhotv.co.uk/', 'URL is not expected')
1198 * .done();
1199 * ```
1200 *
1201 * @api
1202 * @method doesntHaveUrl
1203 * @param {string} expected Expected test result
1204 * @param {string} message Message for the test reporter
1205 * @chainable
1206 */
1207
12081Assertions.prototype.doesntHaveUrl = function (expected, message) {
12090 var hash = uuid.v4();
12100 var cb = this._generateCallbackAssertion('url', '!url', this._testShallowUnequals, hash, {expected: expected, message: message}).bind(this.test);
12110 this._addToActionQueue([expected, hash], 'url', cb);
12120 return this.chaining ? this : this.test;
1213};
1214
1215/**
1216 * Asserts that an elements attribute is as expected.
1217 *
1218 * ```html
1219 * <form>
1220 * <button class="jumpButton" type="submit">Fire</button>
1221 * </form>
1222 * ```
1223 *
1224 * ```javascript
1225 * test
1226 * .open('http://dalekjs.com/guineapig/')
1227 * .assert.attr('.jumpButton', 'type', 'submit')
1228 * .done();
1229 * ```
1230 *
1231 * ```html
1232 * <div id="dataDiv" data-spot="cat"></div>
1233 * ```
1234 *
1235 * ```javascript
1236 * test
1237 * .open('http://dalekjs.com/guineapig/')
1238 * .assert.attr('#dataDiv').is('data-spot', 'cat', 'We found Dataʼs cat!')
1239 * .done();
1240 * ```
1241 *
1242 * ```javascript
1243 * test
1244 * .open('http://dalekjs.com/guineapig/')
1245 * .assert.attr('#dataDiv').is.not('data-spot', 'doc', 'Spot is not a dog!')
1246 * .done();
1247 * ```
1248 *
1249 * @api
1250 * @method attr
1251 * @param {string} selector Selector that matches the elements to test
1252 * @param {string} attribute The attribute to test
1253 * @param {string} expected Expected test result
1254 * @param {string} message Message for the test reporter
1255 * @chainable
1256 */
1257
12581Assertions.prototype.attr = function (selector, attribute, expected, message) {
12590 var hash = uuid.v4();
1260
12610 if (this.test.querying === true) {
12620 message = expected;
12630 expected = attribute;
12640 attribute = selector;
12650 selector = this.test.selector;
1266 }
1267
12680 var cb = this._generateCallbackAssertion('attribute', 'attribute', this._testShallowEquals, hash, {expected: expected, message: message, selector: selector, attribute: attribute}).bind(this.test);
12690 this._addToActionQueue([selector, attribute, expected, hash], 'attribute', cb);
12700 return this.chaining ? this : this.test;
1271};
1272
1273// TEST HELPER
1274// -----------
1275
1276/**
1277 * Is helper
1278 *
1279 * @method is
1280 * @param {mixed} expected Value to check
1281 * @param {string} message Test message
1282 * @chainable
1283 */
1284
12851Assertions.prototype.is = function (expected, message) {
12860 return this.generateTestHelper('is', '_testShallowEquals', false)(expected, message);
1287};
1288
1289/**
1290 * Not helper
1291 *
1292 * @method not
1293 * @param {mixed} expected Value to check
1294 * @param {string} message Test message
1295 * @chainable
1296 */
1297
12981Assertions.prototype.not = function (expected, message) {
12990 return this.generateTestHelper('not', '_testShallowEquals', true)(expected, message);
1300};
1301
1302/**
1303 * Between helper
1304 *
1305 * @method between
1306 * @param {mixed} expected Value to check
1307 * @param {string} message Test message
1308 * @chainable
1309 */
1310
13111Assertions.prototype.between = function (expected, message) {
13120 return this.generateTestHelper('between', '_testBetween', false)(expected, message);
1313};
1314
1315/**
1316 * Gt helper
1317 *
1318 * @method gt
1319 * @param {mixed} expected Value to check
1320 * @param {string} message Test message
1321 * @chainable
1322 */
1323
13241Assertions.prototype.gt = function (expected, message) {
13250 return this.generateTestHelper('gt', '_testGreaterThan', false)(expected, message);
1326};
1327
1328/**
1329 * Gte helper
1330 *
1331 * @method gte
1332 * @param {mixed} expected Value to check
1333 * @param {string} message Test message
1334 * @chainable
1335 */
1336
13371Assertions.prototype.gte = function (expected, message) {
13380 return this.generateTestHelper('gte', '_testGreaterThanEqual', false)(expected, message);
1339};
1340
1341/**
1342 * Lt helper
1343 *
1344 * @method lt
1345 * @param {mixed} expected Value to check
1346 * @param {string} message Test message
1347 * @chainable
1348 */
1349
13501Assertions.prototype.lt = function (expected, message) {
13510 return this.generateTestHelper('lt', '_testLowerThan', false)(expected, message);
1352};
1353
1354/**
1355 * Lte helper
1356 *
1357 * @method lte
1358 * @param {mixed} expected Value to check
1359 * @param {string} message Test message
1360 * @chainable
1361 */
1362
13631Assertions.prototype.lte = function (expected, message) {
13640 return this.generateTestHelper('lte', '_testLowerThanEqual', false)(expected, message);
1365};
1366
1367/**
1368 * Contain helper
1369 *
1370 * @method contain
1371 * @param {mixed} expected Value to check
1372 * @param {string} message Test message
1373 * @chainable
1374 */
1375
13761Assertions.prototype.contain = function (expected, message) {
13770 return this.generateTestHelper('contain', '_contain', false)(expected, message);
1378};
1379
1380/**
1381 * Match helper
1382 *
1383 * @method match
1384 * @param {string} expected Regex to match on
1385 * @param {string} message Test message
1386 * @chainable
1387 */
1388
13891Assertions.prototype.match = function (expected, message) {
13900 return this.generateTestHelper('match', '_match', false)(expected, message);
1391};
1392
1393// HELPER METHODS
1394// --------------
1395
1396/**
1397 * Generates a callback that will be fired when the action has been completed.
1398 * The callback itself will then validate the answer and will also emit an event
1399 * that the action has been successfully executed.
1400 *
1401 * @method _generateCallbackAssertion
1402 * @param {string} key Unique key of the action
1403 * @param {string} type Type of the action (usually the actions name)
1404 * @return {function} The generated callback function
1405 * @private
1406 */
1407
14081Assertions.prototype._generateCallbackAssertion = function (key, type, test, hash, opts) {
14090 var cb = function (data) {
14100 if (data && data.key === key && data.hash === hash) {
1411
14120 this._lastGeneratedAction = {key: key, type: type, test: test, hash: hash, opts: opts, data: data};
1413
14140 if (!opts.expected && (key === 'title' || key === 'width' || key === 'height' || key === 'url' || key === 'text' || key === 'attribute' || key === 'numberOfElements' || key === 'numberOfVisibleElements')) {
14150 return false;
1416 }
1417
14180 if (typeof opts.expected === 'function') {
14190 opts.expected = opts.expected();
1420 }
1421
14220 var testResult = test(data.value, opts.expected);
1423
14240 this.reporter.emit('report:assertion', {
1425 success: testResult,
1426 expected: opts.expected,
1427 value: data.value,
1428 message: opts.message,
1429 type: type
1430 });
1431
14320 this.incrementExpectations();
14330 if (!testResult) {
14340 this.incrementFailedAssertions();
1435 }
1436 }
1437 };
14380 return cb;
1439};
1440
1441/**
1442 * Adds a method to the queue of actions/assertions to execute
1443 *
1444 * @method _addToActionQueue
1445 * @param {object} opts Options of the action to invoke
1446 * @param {string} driverMethod Name of the method to call on the driver
1447 * @param {function} A callback function that will be executed when the action has been executed
1448 * @private
1449 * @chainable
1450 */
1451
14521Assertions.prototype._addToActionQueue = function (opts, driverMethod, cb) {
14530 this._lastGeneratedShit = {opts: opts, driverMethod: driverMethod};
14540 this.test.actionPromiseQueue.push(function () {
14550 var deferredAction = Q.defer();
14560 this.test.driver[driverMethod].apply(this.test.driver, opts);
14570 deferredAction.resolve();
14580 this.test.driver.events.on('driver:message', cb);
14590 return deferredAction.promise;
1460 }.bind(this));
14610 return this;
1462};
1463
1464/**
1465 * Generates a function that can be used
1466 *
1467 * @method generateTestHelper
1468 * @param name
1469 * @param assertionFn
1470 * @param negate
1471 * @return
1472 * @private
1473 */
1474
14751Assertions.prototype.generateTestHelper = function (name, assertionFn, negate) {
14760 return function (expected, message) {
14770 var gen = this._lastGeneratedShit;
1478
14790 this.test.actionPromiseQueue.push(function () {
14800 var deferredAction = Q.defer();
14810 deferredAction.resolve();
14820 this.test.driver.events.on('driver:message', function () {
1483
14840 if (gen.opts && gen.opts[(gen.opts.length - 1)] && this.test._lastGeneratedAction && this.test._lastGeneratedAction.hash) {
14850 if (gen.opts[(gen.opts.length - 1)] === this.test._lastGeneratedAction.hash && !this.proceeded[this.test._lastGeneratedAction.hash + name]) {
14860 var testResult = this[assertionFn](expected, this.test._lastGeneratedAction.data.value);
1487
14880 if (negate) {
14890 testResult = !testResult;
1490 }
1491
14920 this.proceeded[this.test._lastGeneratedAction.hash + name] = true;
1493
14940 this.test.reporter.emit('report:assertion', {
1495 success: testResult,
1496 expected: expected,
1497 value: this.test._lastGeneratedAction.data.value,
1498 message: message,
1499 type: this.test._lastGeneratedAction.type
1500 });
1501
15020 this.test.incrementExpectations();
1503
15040 if (!testResult) {
15050 this.test.incrementFailedAssertions();
1506 }
1507 }
1508 }
1509 }.bind(this));
15100 return deferredAction.promise;
1511 }.bind(this));
1512
15130 return this.chaining ? this : this.test;
1514 }.bind(this);
1515};
1516
1517// ASSERT METHODS
1518// --------------
1519
1520/**
1521 * Assert if a given value shallow equals a second given value
1522 *
1523 * @method _testShallowEquals
1524 * @param {mixed} a Value to test
1525 * @param {mixed} b Value to test
1526 * @return {bool} false if values donʼt match, true if they match
1527 * @private
1528 */
1529
15301Assertions.prototype._testShallowEquals = function (a, b) {
15310 try {
15320 chai.assert.equal(a, b);
1533 } catch (e) {
15340 return false;
1535 }
1536
15370 return true;
1538};
1539
1540/**
1541 * Assert if a given value shallow does not equal a second given value
1542 *
1543 * @method _testShallowUnequals
1544 * @param {mixed} a Value to test
1545 * @param {mixed} b Value to test
1546 * @return {bool} true if values donʼt match, false if they match
1547 * @private
1548 */
1549
15501Assertions.prototype._testShallowUnequals = function (a, b) {
15510 try {
15520 chai.assert.notEqual(a, b);
1553 } catch (e) {
15540 return false;
1555 }
1556
15570 return true;
1558};
1559
1560/**
1561 * Assert if a given value matches a range
1562 *
1563 * @method _testBetween
1564 * @param {array} a Range to test
1565 * @param {bool} b Value to compare
1566 * @return {bool} test result
1567 * @private
1568 */
1569
15701Assertions.prototype._testBetween = function (a, b) {
15710 try {
15720 chai.expect(b).to.be.within(a[0], a[1]);
1573 } catch (e) {
15740 return false;
1575 }
1576
15770 return true;
1578};
1579
1580/**
1581 * Assert if a given value is greater than the value to compare
1582 *
1583 * @method _testGreaterThan
1584 * @param {bool} a Value to test
1585 * @param {bool} b Value to compare
1586 * @return {bool} test result
1587 * @private
1588 */
1589
15901Assertions.prototype._testGreaterThan = function (a, b) {
15910 try {
15920 chai.expect(b).to.be.above(a);
1593 } catch (e) {
15940 return false;
1595 }
1596
15970 return true;
1598};
1599
1600/**
1601 * Assert if a given value is greater or equal than the value to compare
1602 *
1603 * @method _testGreaterThanEqual
1604 * @param {bool} a Value to test
1605 * @param {bool} b Value to compare
1606 * @return {bool} test result
1607 * @private
1608 */
1609
16101Assertions.prototype._testGreaterThanEqual = function (a, b) {
16110 return this._testGreaterThan(a - 1, b);
1612};
1613
1614/**
1615 * Assert if a given value is lower than the value to compare
1616 *
1617 * @method _testLowerThan
1618 * @param {bool} a Value to test
1619 * @param {bool} b Value to compare
1620 * @return {bool} test result
1621 * @private
1622 */
1623
16241Assertions.prototype._testLowerThan = function (a, b) {
16250 try {
16260 chai.expect(b).to.be.below(a);
1627 } catch (e) {
16280 return false;
1629 }
1630
16310 return true;
1632};
1633
1634/**
1635 * Assert if a given value contain another value
1636 *
1637 * @method _contain
1638 * @param {bool} a Value to test
1639 * @param {bool} b Value to compare
1640 * @return {bool} test result
1641 * @private
1642 */
1643
16441Assertions.prototype._contain = function (a, b) {
16450 try {
16460 chai.expect(b).to.include(a);
1647 } catch (e) {
16480 return false;
1649 }
1650
16510 return true;
1652};
1653
1654/**
1655 * Assert if a given value is lower or equal than the value to compare
1656 *
1657 * @method _testLowerThanEqual
1658 * @param {bool} a Value to test
1659 * @param {bool} b Value to compare
1660 * @return {bool} test result
1661 * @private
1662 */
1663
16641Assertions.prototype._testLowerThanEqual = function (a, b) {
16650 return this._testLowerThan(a + 1, b);
1666};
1667
1668/**
1669 * Assert if a given value is boolean 'true'
1670 *
1671 * @method _testTruthy
1672 * @param {bool} a Value to test
1673 * @return {bool} false if value is false, true if value is true
1674 * @private
1675 */
1676
16771Assertions.prototype._testTruthy = function (a) {
16780 return a === 'true' || a === true;
1679};
1680
1681/**
1682 * Assert if a given value is boolean 'false'
1683 *
1684 * @method _testFalsy
1685 * @param {bool} a Value to test
1686 * @return {bool} true if value is false, false if value is true
1687 * @private
1688 */
1689
16901Assertions.prototype._testFalsy = function (a) {
16910 return a === 'false' || a === false;
1692};
1693
1694/**
1695 * Assert a given value matches a RegEx
1696 *
1697 * @method _contain
1698 * @param {mixed} a Value to test
1699 * @param {string} b Value to compare
1700 * @return {bool} test result
1701 * @private
1702 */
1703
17041Assertions.prototype._match = function (a, b) {
17050 try {
17060 chai.expect(b).to.match(a);
1707 } catch (e) {
17080 return false;
1709 }
1710
17110 return true;
1712};
1713