.. _jasmine_module:
======================
The ``jasmine`` Module
======================
``jasmine``
-----------
see the `jasmine
123
") will return true if the ``#target`` is contains "123
" :: toContainHtml: function (html) { var nodeList = jQuery(this.actual).first(); var allHtml = nodeList.html() || ""; return allHtml.indexOf(html) != -1; }, ``toContainText(text)`` ~~~~~~~~~~~~~~~~~~~~~~~ Example: :: expect("#target").toContainText(123) will return true if the ``#target`` is contains text "123" :: toContainText: function (text) { var nodeList = jQuery(this.actual); var trimmedText = jQuery.trim(nodeList.text()) || ""; return trimmedText.indexOf(text) != -1; } ``toHaveValue(value)`` ~~~~~~~~~~~~~~~~~~~~~~ **value** ``String`` the value you wanna to test Example: :: expect("#target").toHaveValue("123") will return true if the ``#target`` is has value "123" :: toHaveValue: function (value) { var node = jQuery(this.actual).first(); return node.val() === value; } ``toBeDisabled()`` ~~~~~~~~~~~~~~~~~~ Example: :: expect("#target").toBeDisabled() will return true if the ``#target`` is disabled :: toBeDisabled: function (selector) { var nodeList = jQuery(this.actual); if (nodeList.size() == 0) return false; return nodeList.filter(':disabled').size() == nodeList.size(); } ``toBeFocused()`` ~~~~~~~~~~~~~~~~~ Example: :: expect("#target").toBeFocused() will return true if the ``#target`` is being focused :: toBeFocused: function () { var nodeList = jQuery(this.actual); if (nodeList.size() == 0) return false; return nodeList.filter(':focus').size() == nodeList.size(); } ``toHaveCSS`` ~~~~~~~~~~~~~~~~~ Example: :: expect("#target").toHaveCSS("color","#fff") will return true if the ``#target`` has css "color:#fff" :: toHaveCSS: function (styleProp, expectValue) { if (styleProp.match(/color/i)) { var tempNode = $(''); $('body').append(tempNode); $(tempNode).css(styleProp, expectValue); expectValue = $(tempNode).css(styleProp); tempNode.remove(); } return jQuery(this.actual).first().css(styleProp) === expectValue; } ``atPosition(x, y, off, relativeEl)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **x** ``String`` left value **y** ``String`` top value **off** ``String`` .. index:: position Example: :: expect("#target").atPosition(0,0) will return true if the ``#target`` is at position 0,0 :: atPosition: function (x, y, off, relativeEl) { var tempOff = 0.1; var absX = Math.abs(x); var absY = Math.abs(y); var referPosition = {top: 0, left: 0}; if (arguments[2] && typeof arguments[2] == 'number') { tempOff = arguments[2]; } if (arguments[3] && typeof arguments[3] == 'string') { var referEl = jQuery(arguments[3]); if (referEl) { referPosition = referEl.offset(); } } var nodeList = jQuery(this.actual); var actualPosition = nodeList.offset(); var heightGap = nodeList.outerHeight() * tempOff; var widthGap = nodeList.outerWidth() * tempOff; return (Math.abs(Math.abs(actualPosition.top - referPosition.top) - absY) < heightGap) && ( Math.abs(Math.abs(actualPosition.left - referPosition.left) - absX) < widthGap); } ``toHaveComputedStyle(styleProp, expectValue)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. index:: computed style Example: :: expect("#target").toHaveComputedStyle('color','#fff') will return true if the ``#target`` has computed style :: toHaveComputedStyle: function (styleProp, expectValue) { if (styleProp.match(/color/i)) { var tempNode = $(''); $('body').append(tempNode); $(tempNode).css(styleProp, expectValue); expectValue = $(tempNode).css(styleProp); tempNode.remove(); } return jQuery(this.actual).first().css(styleProp) === expectValue; }, ``toHaveChildren(selector, num)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. index:: children Example: :: expect("#target").toHaveChildren('#targetChild', 1) will return true if the ``#target`` has 1 child which id is 'targetChild' :: toHaveChildren: function (selector, num) { return jQuery(this.actual).children(selector).length == num; }, ``toHaveAttr(attributeName, expectedAttributeValue)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. index:: attr attribute Example: :: expect("#target").toHaveAttr('class', 'target') will return true if the ``#target`` has "class" that equal "target" :: toHaveAttr: function (attributeName, expectedAttributeValue) { var nodeList = jQuery(this.actual); if (nodeList.length == 0)return false; var result = true; jQuery.each(nodeList, function (index, item) { if (jQuery(item).attr(attributeName) != expectedAttributeValue) { result = false; return false; } }) return result; } ``toHaveAttr(attributeName, expectedAttributeValue)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. index:: attr attribute Example: :: expect("#target").toHaveAttr('class', 'target') will return true if the ``#target`` has "class" that equal "target" :: toHaveAttr: function (attributeName, expectedAttributeValue) { var nodeList = jQuery(this.actual); if (nodeList.length == 0)return false; var result = true; jQuery.each(nodeList, function (index, item) { if (jQuery(item).attr(attributeName) != expectedAttributeValue) { result = false; return false; } }) return result; }