jeudi 16 avril 2015

How to Unit Test JavaScript function that detects the browser?

How could I test that this function does what it is supposed to do? I am working with Jasmine as Testing framework.



function () { //if IE, return version number
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');

if (msie > 0) { // IE 10 or older
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}

if (trident > 0) { // IE 11 (or newer)
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}

// other browser
return false;
}


I don't mind if this function works or not. I need to write a test for it. This means it doesn't help me if you tell me it works.


Aucun commentaire:

Enregistrer un commentaire