Created
January 19, 2015 09:57
-
-
Save robinduckett/41644baa2748b90fe7b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 $j = (function($j) { | |
var funcs = [ | |
'on', 'hide', 'is', 'toggle', 'html', 'parent' | |
]; | |
var events = {}; | |
funcs.forEach(function(func) { | |
events[func] = sinon.spy(jQuery.fn, func); | |
}); | |
function jexpect(selector) { | |
this.selector = selector; | |
this.events = events; | |
this.stubs = {}; | |
} | |
funcs.forEach(function(evt) { | |
jexpect.prototype[evt] = function(arg) { | |
var calls = []; | |
this.events[evt].thisValues.forEach(function(item, index) { | |
if (item.selector === this.selector) { | |
if (this.events[evt].args[index][0] === arg) { | |
calls.push(this.events[evt].getCall(index)); | |
} | |
} | |
}.bind(this)); | |
if (calls.length === 0) { | |
this.stubs[this.selector] = sinon.stub(jQuery.fn, evt); | |
return this.events[evt]; | |
} | |
return calls[0]; | |
} | |
}); | |
return $j = function(selector) { | |
return new jexpect(selector); | |
}; | |
})($j); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment