2011-12-15 15:12:54 +01:00
|
|
|
|
|
|
|
// JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
|
|
|
|
|
|
JSpec
|
|
|
|
.requires('jQuery', 'when using jspec.jquery.js')
|
|
|
|
.include({
|
|
|
|
name: 'jQuery',
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
// --- Initialize
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
init : function() {
|
|
|
|
jQuery.ajaxSetup({ async: false })
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
// --- Utilities
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
utilities : {
|
|
|
|
element: jQuery,
|
|
|
|
elements: jQuery,
|
|
|
|
sandbox : function() {
|
|
|
|
return jQuery('<div class="sandbox"></div>')
|
|
|
|
}
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
// --- Matchers
|
2016-01-06 00:34:58 +01:00
|
|
|
|
|
|
|
matchers : {
|
2011-12-15 15:12:54 +01:00
|
|
|
have_tag : "jQuery(expected, actual).length === 1",
|
|
|
|
have_one : "alias have_tag",
|
|
|
|
have_tags : "jQuery(expected, actual).length > 1",
|
|
|
|
have_many : "alias have_tags",
|
|
|
|
have_any : "alias have_tags",
|
|
|
|
have_child : "jQuery(actual).children(expected).length === 1",
|
|
|
|
have_children : "jQuery(actual).children(expected).length > 1",
|
|
|
|
have_text : "jQuery(actual).text() === expected",
|
|
|
|
have_value : "jQuery(actual).val() === expected",
|
|
|
|
be_enabled : "!jQuery(actual).attr('disabled')",
|
|
|
|
have_class : "jQuery(actual).hasClass(expected)",
|
2016-01-06 00:34:58 +01:00
|
|
|
be_animated : "jQuery(actual).queue().length > 0",
|
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
be_visible : function(actual) {
|
|
|
|
return jQuery(actual).css('display') != 'none' &&
|
|
|
|
jQuery(actual).css('visibility') != 'hidden' &&
|
|
|
|
jQuery(actual).attr('type') != 'hidden'
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
be_hidden : function(actual) {
|
|
|
|
return !JSpec.does(actual, 'be_visible')
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
have_classes : function(actual) {
|
|
|
|
return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
|
|
|
|
return !JSpec.does(actual, 'have_class', arg)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
have_attr : function(actual, attr, value) {
|
|
|
|
return value ? jQuery(actual).attr(attr) == value:
|
|
|
|
jQuery(actual).attr(attr)
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
have_event_handlers : function(actual, expected) {
|
|
|
|
if (jQuery(actual).data('events') && jQuery(actual).data('events').hasOwnProperty(expected)) {
|
|
|
|
return true;
|
|
|
|
} else if (jQuery(actual.context).data('events') && jQuery(actual.context).data('events').hasOwnProperty(expected)) {
|
|
|
|
var events = jQuery(actual.context).data('events')[expected];
|
|
|
|
|
|
|
|
for (index in events) {
|
|
|
|
if (events[index].selector === actual.selector) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
'be disabled selected checked' : function(attr) {
|
|
|
|
return 'jQuery(actual).attr("' + attr + '")'
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
'have type id title alt href src sel rev name target' : function(attr) {
|
|
|
|
return function(actual, value) {
|
|
|
|
return JSpec.does(actual, 'have_attr', attr, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|