Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw when component is missing #4

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions lib/h.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const flatten = require('lodash.flattendeep');
const VNode = require('./vnode');

module.exports = (component, props, ...children) => {
if (typeof component !== 'function' && typeof component !== 'string') {
throw new TypeError(`ink.h: expected component to be a function, but received "${component}". You may have forgotten to export a component.`);
Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove ink.h and start with Expected?

Also, replace "${component}" with typeof component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}

props = props || {};

const readyChildren = [];
Expand Down
7 changes: 7 additions & 0 deletions test/h.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,10 @@ test.failing('don\'t merge children of components', t => {

t.deepEqual(node.props.children, ['x', 'y']);
});

test('warns on invalid type', t => {
Copy link
Owner

Choose a reason for hiding this comment

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

warns => throws
invalid type => missing component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

t.throws(() => {
Copy link
Owner

Choose a reason for hiding this comment

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

=> t.throws(() => h(), 'Expected component to be a function, got undefined. You may have forgotten to export a component.');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

h(undefined);
});
});