vendredi 4 septembre 2015

How to set document.body.scrollHeight for unit testing in jasmine

I want to test my function which calculates table height.

        self.tableHeight = function() {
            var tableContentOffsetTop = angular.element(document.getElementById("contentTable")).prop("offsetTop"),
                body = document.body,
                html = document.documentElement,
                clientHeight = Math.max(body.scrollHeight,
                                    body.offsetHeight,
                                    html.clientHeight,
                                    html.scrollHeight,
                                    html.offsetHeight);
            return (parseInt(clientHeight, 10) - tableContentOffsetTop);
        };

I tried to set the document height and also set the table offsetTop using

        document.body.scrollHeight = 1000;
        document.body.offsetHeight = 1000;
        document.documentElement.scrollHeight = 1000;
        document.documentElement.clientHeight = 1000;
        document.documentElement.offsetHeight = 1000;
       angular.element(document.getElementById("contentTable")).offSetTop = 250;

However I couldn't set the document Height as they already have some value and it wasn't getting overridden while I set the new height or offSetTop. Can anyone help me figure out how to unit test my function?. I am using jasmine for my unit testing.

Aucun commentaire:

Enregistrer un commentaire