Skip to content

Commit

Permalink
#1030@trivial: Fixes failing unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Sep 6, 2023
1 parent 67608e5 commit b19d2d1
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions packages/jest-environment/test/javascript/JavaScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,39 +141,4 @@ describe('JavaScript', () => {
removeEventListener('click', eventListener);
clearTimeout(setTimeout(eventListener));
});

it('Catches unhandled rejections', async () => {
const express = Express();

express.get('/get/json', (_req, res) => {
res.set('Content-Type', 'application/json');
res.send('{ "key1": "value1" }');
});

const server = express.listen(3000);

let errorEvent: ErrorEvent | null = null;
window.addEventListener('error', (event: ErrorEvent) => (errorEvent = <ErrorEvent>event));

document.write(`
<script>
(() => {
async function main() {
await fetch('http://localhost:3000/get/json');
throw new Error('Test error');
}
main();
})();
</script>
`);

await new Promise((resolve) => setTimeout(resolve, 100));

server.close();

expect(errorEvent).toBeInstanceOf(ErrorEvent);
expect(errorEvent.error.message).toBe('Test error');
expect(errorEvent.message).toBe('Test error');
});
});

0 comments on commit b19d2d1

Please sign in to comment.