Skip to content

Instantly share code, notes, and snippets.

@justinfagnani
Created October 8, 2017 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfagnani/60df7ff7744acbea197e72c85add260e to your computer and use it in GitHub Desktop.
Save justinfagnani/60df7ff7744acbea197e72c85add260e to your computer and use it in GitHub Desktop.
Web Components Conformance Tests
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