Last active
January 1, 2016 21:58
-
-
Save frozeman/8206698 to your computer and use it in GitHub Desktop.
jQuery testing stubs.
Where the stub can be overwritten e.g. by setting jQueryStub.prototype.find = ...;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $, jQueryStub; | |
(function () { | |
"use strict"; | |
var emptyFunction = function () { | |
}; | |
var selfReturn = function(){ | |
return new jQueryStub(); | |
}; | |
jQueryStub = function () { | |
}; | |
jQueryStub.prototype = { | |
onEventMap: {}, | |
ready: emptyFunction, | |
show: emptyFunction, | |
scroll: emptyFunction, | |
scrollTop: emptyFunction, | |
val: emptyFunction, | |
each: emptyFunction, | |
attr: emptyFunction, | |
done: emptyFunction, | |
hide: emptyFunction, | |
focus: emptyFunction, | |
off: emptyFunction, | |
length: 0, | |
text: function(){ | |
return { | |
attr: emptyFunction | |
}; | |
}, | |
on: function (eventKey, eventFunction) { | |
jQueryStub.prototype.onEventMap[eventKey] = eventFunction; | |
}, | |
fireOnEvent: function (key, eventObject) { | |
jQueryStub.prototype.onEventMap[key](eventObject); | |
}, | |
trigger: function(eventKey){ | |
jQueryStub.prototype.onEventMap[eventKey](); | |
}, | |
fn: {}, | |
addedClasses: [], | |
addClass: function (className) { | |
jQueryStub.prototype.addedClasses.push(className); | |
}, | |
data: function() { | |
return; | |
}, | |
scrollLeft: function() { | |
}, | |
html: selfReturn, | |
find: selfReturn, | |
parents: selfReturn, | |
parent: selfReturn, | |
width: selfReturn, | |
innerWidth: selfReturn, | |
css: selfReturn | |
}; | |
$ = function () { | |
return new jQueryStub(); | |
}; | |
$.ajax = function(){ | |
return { | |
done: emptyFunction | |
}; | |
}; | |
$.getJSON = emptyFunction; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment