Skip to content

Commit

Permalink
Port skipped "test_body_event_handler_inline" to WPT
Browse files Browse the repository at this point in the history
Co-Authored-By: Timothy Gu <timothygu99@gmail.com>
  • Loading branch information
ExE-Boss and TimothyGu committed Mar 28, 2021
1 parent a13d854 commit c1b9ea1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
31 changes: 0 additions & 31 deletions test/to-port-to-wpts/misc2.js
Expand Up @@ -385,37 +385,6 @@ describe("jsdom/miscellaneous", () => {
assert.ok(a.getAttribute("style").match(/^\s*width\s*:\s*100%\s*;?\s*$/), "style attribute must contain width");
});

// Test inline event handlers set on the body.
// TODO this currently fails!?
specify.skip("test_body_event_handler_inline", { skipIfBrowser: true, async: true }, t => {
// currently skipped in browsers because of an issue:
// TODO: https://github.com/jsdom/jsdom/issues/1379
const html = `
<html>
<head>
<script>
function loader () {
window.loader_called = true;
}
</script>
</head>
<body onload="loader()"></body>
</html>`;
const doc = (new JSDOM(html, { runScripts: "dangerously" })).window.document;
const window = doc.defaultView;
// In JSDOM, listeners registered with addEventListener are called before
// "traditional" listeners, so listening for "load" will fire before our
// inline listener. This means we have to check the value on the next
// tick.
window.addEventListener("load", () => {
process.nextTick(() => {
assert.equal(window.loader_called, true);
t.done();
});
});
doc.close();
});

specify("get_element_by_id", () => {
const doc = (new JSDOM()).window.document;
const el = doc.createElement("div");
Expand Down
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test inline event handlers set on the body.</title>
<link rel="author" title="Timothy Gu" href="mailto:timothygu99@gmail.com">
<link rel="help" href="https://github.com/jsdom/jsdom/issues/1379">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>

<script>
"use strict";
setup({ single_test: true });

// eslint-disable-next-line no-unused-vars
function onloadHandler() {
window.loader_called = true;
}
</script>

<body onload="onloadHandler()">
<div id=log></div>
<script>
"use strict";
window.addEventListener("load", () => {
assert_true(window.loader_called);
done();
});
</script>
</body>

0 comments on commit c1b9ea1

Please sign in to comment.