Skip to content

Commit

Permalink
Ensure Components are instances of HTMLElement
Browse files Browse the repository at this point in the history
Fixes #127
  • Loading branch information
matthewpblog committed Aug 26, 2019
1 parent 572f452 commit d9d165c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function makeComponent(Container) {
}

const proto = new Proxy(BaseElement.prototype, {
getPrototypeOf(target) {
return target;
},

set(target, key, value, receiver) {
if(key in target) {
Reflect.set(target, key, value);
Expand Down
12 changes: 11 additions & 1 deletion test/test-export.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { component, html } from '../haunted.js';
import { attach, cycle } from './helpers.js';

describe('Component exports', () => {
describe('component()', () => {
it('works', async () => {
customElements.define('exports-test', component(() => {
return html`Test`;
Expand All @@ -13,4 +13,14 @@ describe('Component exports', () => {
assert.equal(host.firstChild.shadowRoot.firstChild.nextSibling.nodeValue, 'Test', 'Rendered');
teardown();
});

it('Is an instance of HTMLElement', () => {
const tag = 'component-instanceof';
customElements.define(tag, component(() => {
return html`Test`;
}));

const el = document.createElement(tag);
assert.ok(el instanceof HTMLElement, 'Is an HTMLElement');
});
});

0 comments on commit d9d165c

Please sign in to comment.