describe(`[web-components] supportsPrefetch`, () => { beforeEach(() => jest.resetModules()); const subject = () => { const supportsPrefetch = require('../supports-prefetch').supportsPrefetch; return supportsPrefetch(); }; test('returns false', () => { expect(subject()).toBe(false); }); describe('when prefetch is supported', () => { beforeEach(() => { const mockLink = { relList: { supports: (prop: string) => prop === 'prefetch' }, } as any; jest.spyOn(document, 'createElement').mockImplementation(tag => { return tag === 'link' ? mockLink : (undefined as any); }); }); test('returns true', () => { expect(subject()).toBe(true); }); }); });