Skip to content

Commit fa22cd8

Browse files
committed
trying to get the DOM tests working
1 parent 62b2883 commit fa22cd8

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dom.ts

+11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ class DomContextFactory implements ErrorReportContextFactory {
3838
}
3939

4040
export function catchDomErrors(configuration: Configuration) {
41+
window.document.addEventListener('error', (event: ErrorEvent) => {
42+
console.log('ERROR#¤#"¤¤#"!');
43+
const domContext = new DomErrorContext(
44+
event.target,
45+
event.error,
46+
window.document,
47+
window
48+
);
49+
Reporter.instance.reportByContext(domContext);
50+
});
4151
window.addEventListener('error', (event: ErrorEvent) => {
52+
console.log('ERROR#¤#"¤¤#"!');
4253
const domContext = new DomErrorContext(
4354
event.target,
4455
event.error,

tests/dom_spec.ts

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
import { expect } from 'chai';
22
import 'mocha';
3-
import { JSDOM } from 'jsdom';
3+
import { JSDOM, VirtualConsole } from 'jsdom';
44
import { ContextCollectionProviderContext } from '../src/interfaces';
55
import { Configuration, Reporter } from '../src/reporting';
66
import { ErrorReportDTO, ErrorDTO } from '../src/contracts';
77
import { catchDomErrors } from '../src/dom';
88
declare var global: any;
99

10+
const html = `<!DOCTYPE html>
11+
<html>
12+
<head>
13+
<title>hello</title>
14+
<script>
15+
function crash()
16+
{
17+
console.log('here');
18+
//document.getElementById('abc').innerHTML = 'hello';
19+
throw new Error("Testar");
20+
}
21+
</script>
22+
</head>
23+
<body>
24+
</body>
25+
</html>`;
26+
27+
const virtualConsole = new VirtualConsole();
28+
virtualConsole.sendTo(console);
29+
virtualConsole.on("error", () => { console.log('ERRRRRROR'); });
30+
virtualConsole.on("jsdomError", (e) => {
31+
console.log(e);
32+
})
33+
//virtualConsole.on("log", () => { });
34+
1035
const config = new Configuration('a', 'b');
11-
const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>');
36+
const dom = new JSDOM(html, {runScripts: "dangerously", virtualConsole});
37+
38+
dom.window.addEventListener('error', function(){console.log('ERROR!!')});
1239
global.window = dom.window;
1340
global.document = dom.window.document;
1441

@@ -23,7 +50,7 @@ describe('DOM error event', () => {
2350
it('includes the document collection', () => {
2451
catchDomErrors(config);
2552

26-
dom.window.document.body.innerHTML = '<script>a = 10 / 0;</script>';
53+
global.window.eval('crash()');
2754

2855
expect(actualContext).to.be('object');
2956
});

0 commit comments

Comments
 (0)