js-web-tools
Version:
Tools for Javascript develpers
40 lines (35 loc) • 1.07 kB
JavaScript
;
var _domElementSize = require("../domElementSize");
function createMockElement(width, height) {
var top = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var left = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
var newEle = document.createElement("div");
newEle.style.cssText = "width:".concat(width, "px;height:").concat(height, "px;");
newEle.getBoundingClientRect = function () {
return {
width: width,
height: height,
top: top,
left: left,
right: width,
bottom: height
};
};
return newEle;
}
describe('Size', function () {
var mockEle = null;
beforeEach(function () {
mockEle = createMockElement(300, 400);
document.body.appendChild(mockEle);
});
afterEach(function () {
document.body.removeChild(mockEle);
});
it('should get target width', function () {
var w = (0, _domElementSize.width)(mockEle);
var h = (0, _domElementSize.height)(mockEle);
expect(w).toEqual(300);
expect(h).toEqual(400);
});
});