Could anybody help me to test this simple function please? I have to write a test in JASMINE for the function check_if_mobile_width(). After long serching I tried with Jasmine Spy but don't understand how it exactly works... I always get this error: "Expected spy addClass to have been called. (1)"
Function:
function check_if_mobile_width() {
if ($(window).width() < 979) {
$.root_.addClass('mobile-view-activated')
} else if ($.root_.hasClass('mobile-view-activated')) {
$.root_.removeClass('mobile-view-activated');
}}
TEST:
describe("desktop or mobile -- check_if_mobile_width()", function(){
it("should return the kind of the device", function(){
check_if_mobile_width();
spyOn($.root_, "addClass");
spyOn($.root_, "removeClass");
if($(window).width() < 979)
expect($.root_.addClass).toHaveBeenCalled();
else
expect($.root_.removeClass).toHaveBeenCalled();
});
});
Aucun commentaire:
Enregistrer un commentaire