export function tryAddELement(){
const link = document.createElement('a');
link.href = 'sampleHref';
}
Im trying to write a Jest test for this, but I am stuck on creating the mock HTML element.
it('test tryAddElement', () => {
// const elementMock; // Stuck here
// const createElementMock = jest.spyOn(document, "createElement").mockReturnValue(elementMock);
tryAddELement();
});
How do we mock a HMTL element in Jest?
Something like this:
it('test tryAddElement', () => {
tryAddELement();
const expectedElement = document.getElementsByTagName("a[href='sampleHref']");
expect(expectedElement).toBeTruthy();
});