Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 302575f

Browse files
authored
Merge pull request #49 from joscha/better-error-handling
fix: provide better error message if the contructor passed is not valid
2 parents b772384 + 64ad669 commit 302575f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function syncEvent(node, eventName, newEventHandler) {
2828

2929
export default function (CustomElement, opts) {
3030
opts = assign({}, defaults, opts);
31+
if (typeof CustomElement !== 'function') {
32+
throw new Error('Given element is not a valid constructor');
33+
}
3134
const tagName = (new CustomElement()).tagName;
3235
const displayName = pascalCase(tagName);
3336
const { React, ReactDOM } = opts;

test/unit/errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import reactify from '../../src/index';
33
describe('prop-types', () => {
44
const msg = 'or passed via opts.';
55

6+
it('no custom element', () => {
7+
expect(() => reactify()).to.throw('Given element is not a valid constructor');
8+
});
9+
610
it('no react', () => {
711
expect(() => reactify(document.registerElement('x-errors-1'), { React: null })).to.throw(msg);
812
expect(() => reactify(document.registerElement('x-no-errors-1'))).to.not.throw(msg);

0 commit comments

Comments
 (0)