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

fix: provide better error message if the contructor passed is not valid #49

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function syncEvent(node, eventName, newEventHandler) {

export default function (CustomElement, opts) {
opts = assign({}, defaults, opts);
if (typeof CustomElement !== 'function') {
throw new Error('Given element is not a valid constructor');
}
const tagName = (new CustomElement()).tagName;
const displayName = pascalCase(tagName);
const { React, ReactDOM } = opts;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import reactify from '../../src/index';
describe('prop-types', () => {
const msg = 'or passed via opts.';

it('no custom element', () => {
expect(() => reactify()).to.throw('Given element is not a valid constructor');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

});

it('no react', () => {
expect(() => reactify(document.registerElement('x-errors-1'), { React: null })).to.throw(msg);
expect(() => reactify(document.registerElement('x-no-errors-1'))).to.not.throw(msg);
Expand Down