diff --git a/lib/h.js b/lib/h.js index b91eeeac2..276768794 100644 --- a/lib/h.js +++ b/lib/h.js @@ -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(`Expected component to be a function, but received ${typeof component}. You may have forgotten to export a component.`); + } + props = props || {}; const readyChildren = []; diff --git a/test/h.js b/test/h.js index 685350097..5deeb4066 100644 --- a/test/h.js +++ b/test/h.js @@ -2,6 +2,10 @@ import test from 'ava'; import VNode from '../lib/vnode'; import {h} from '..'; +test('throws on missing component', t => { + t.throws(() => h(), 'Expected component to be a function, but received undefined. You may have forgotten to export a component.'); +}); + test('return a VNode', t => { const node = h('a');