UNPKG

video-ad-sdk

Version:

VAST/VPAID SDK that allows video ads to be played on top of any player

40 lines (30 loc) 1.1 kB
import {createIframe} from '../createIframe' import {supportsSrcdoc} from '../supportsSrcdoc' jest.mock('../supportsSrcdoc') describe('createIframe', () => { beforeEach(() => { ;(supportsSrcdoc as jest.Mock).mockReturnValue(false) }) test('must return an empty Iframe element', async () => { const iframe = await createIframe(document.body, 'test') expect(iframe).toBeInstanceOf(HTMLIFrameElement) expect(iframe).toMatchSnapshot() iframe.parentElement?.removeChild(iframe) }) test('must post a message to notify that is ready', async () => { expect.assertions(1) const handleMessage = ({data}: MessageEvent): void => { expect(data).toBe('test_iframe_ready') } window.addEventListener('message', handleMessage, false) await createIframe(document.body, 'test_iframe') }) test('must throw (reject) if there is a problem creating the iframe', async () => { expect.assertions(1) try { await createIframe(document.createElement('div'), 'test') } catch (error) { expect(error).toBeInstanceOf(Error) } }) })