I have a javascript function which checks if an html
element, el
, is a certain size by checking:
function isOverflow(element: string): boolean {
const el = document.getElementById(element);
return el.scrollHeight > el.clientHeight
}
I want to test my function. How can I set or mock the scrollHeight and clientHeight?
it('test', () => {
const el = document.createElement("p")
el.setAttribute("id", "overflow")
//How to mock these? This doesn't work "Cannot assign to 'scrollHeight' because it is a read-only property"
el.clientHeight = 2;
el.scrollHeight = 1;
expect(component.isOverflow("overflow")).toBe(true);
})