I'm trying to test <video> error handler tag with Jasmine. I'm not sure how to test that if the element is replaced with another element.
Here's my code.
var VideoHandler = (function($) {
var Handler = function(video) {
return {
handleError : function() {
var sources = video.find('source'),
object = video.find('object'),
lastsource = sources[sources.length - 1];
lastsource.addEventListener('error', function (ev) {
var gif = $('<img>');
gif.attr('alt', 'fallback gif');
gif.attr('src', object.attr('data'));
gif.html(video.innerHTML);
video.replaceWith(gif);
console.log(video.clone().html());
}, false);
}
}
};
return Handler;
})($);
This is my test case
it('should swap gif image with broker video', function() {
var video = $('<video>');
var source = $('<source>');
source.attr('src', 'mp4.mp4');
var object = $('<object>');
object.attr('data', 'path_to_gif.gif');
video.append(source, object);
video.trigger('error');
VideoHandler(video).handleError();
expect(video.is('img')).toBeTruthy();
});
Aucun commentaire:
Enregistrer un commentaire