The Facebook JS SDK has the equivalent of jQuery's trigger()
function, FB.Event.fire
that allows you to trigger the handlers you attach for particular events. Its helpful for my unit tests in QUnit. It works basically as you'd expect it to; FB.Event.fire("comment.create", location.href);
fires my handlers for the comment.create
event.
Twitter's object for Web Intents, twttr
appears to have something that looks like it could be similar, twttr.events.trigger()
, but its undocumented.
Except, I can't figure out how to trigger it correctly in code, without it throwing an error.
How can I programmatically test the handlers that I attach to this object?
For code like:
twttr.events.bind("click", function(intent){
console.dir(intent);
});
I'd expect to be able to trigger it by doing something like: twttr.events.trigger("click")
Everything I try results in an error, and I'm not able to decipher the obfuscated source code.
I've put up some basic code on the JSFiddle: http://jsfiddle.net/YL6SN/
target
is supposed to be the DOM element of the Twitter iframe (which is crucial for my testing). – Essex