Created
October 8, 2017 22:38
-
-
Save justinfagnani/60df7ff7744acbea197e72c85add260e to your computer and use it in GitHub Desktop.
Web Components Conformance Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NativeHTMLElement = window.HTMLElement; | |
const documentWrite = document.write; | |
const documentOpen = document.open; | |
window.HTMLElement = class extends NativeHTMLElement { | |
constructor(...args) { | |
console.assert(args.length === 0); | |
super(); | |
} | |
} | |
export const createConformanceWrapper = (testSubject) => | |
class extends testSubject { | |
constructor(...args) { | |
document.write = function() { throw new Error(); }; | |
document.open = function() { throw new Error(); }; | |
this.getAttribute = function () { throw new Error(); }; | |
Object.defineProperty(this, 'attributes', { | |
get() { throw new Error(); } | |
}); | |
// Guards for children, childNodes, firstChild, etc. | |
// Guard for innerHTML? | |
super(args); | |
// It's possible these tests should go in the microtask queue | |
console.assert(this instanceof testSubject, 'Element has wrong prototype'); | |
console.assert(this.hasAttributes() === false, 'Element has attributes'); | |
console.assert(this.hasChildNodes() === false, 'Element has children'); | |
document.write = documentWrite; | |
document.open = documentOpen; | |
delete this.getAttribute; | |
delete this.attributes, | |
// Remove other guards | |
} | |
}; | |
export const runTests(testSubject) { | |
const wrapper = createConformanceWrapper(testSubject); | |
// Create iframe to test parser creation | |
// Create with innerHTML | |
// Create with createElement(); | |
// Adopt into another document | |
// append, remove, append to test multiple connectedCallbacks | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment