Skip to content

Commit

Permalink
proper spy on createElement
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtimid committed Sep 26, 2024
1 parent 8a8a30a commit 3662874
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/snaps-utils/src/iframe.test.browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { spy } from '@metamask/snaps-utils/test-utils';

import { createWindow } from './iframe';

const IFRAME_URL = `http://localhost:4569`;
Expand Down Expand Up @@ -60,16 +62,20 @@ describe('createWindow', () => {
});

it('rejects the promise if contentWindow is not present', async () => {
jest.spyOn(document, 'createElement').mockImplementationOnce(() => {
const iframe = document.createElement('iframe');
Object.defineProperty(iframe, 'contentWindow', { value: null });
return iframe;
});
const createElementSpy = spy(document, 'createElement').mockImplementation(
() => {
const iframe = document.createElement('iframe');
Object.defineProperty(iframe, 'contentWindow', { value: null });
return iframe;
},
);

await expect(
createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID }),
).rejects.toThrow(
`iframe.contentWindow not present on load for job "${MOCK_JOB_ID}".`,
);

createElementSpy.reset();
});
});

0 comments on commit 3662874

Please sign in to comment.