Skip to content

Commit

Permalink
feat(vdom): check context child node type in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
localvoid committed May 14, 2018
1 parent 499b707 commit 8c8f97f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/ivi/__tests__/vnode_context.spec.ts
@@ -0,0 +1,10 @@
import { context, fragment } from "ivi";
import * as h from "ivi-html";

test(`assigning children collection should raise an exception`, () => {
expect(() => (
context({},
fragment(h.div(), h.div())!,
)
)).toThrowError("singular");
});
6 changes: 6 additions & 0 deletions packages/ivi/src/vdom/vnode_factories.ts
Expand Up @@ -226,6 +226,12 @@ export function statefulComponent<P>(
* @returns context node.
*/
export function context<T = {}>(ctx: T, child: VNode): VNode<T> {
/* istanbul ignore else */
if (DEBUG) {
if (child.prev !== child) {
throw new Error("Context node contains an invalid child. Child should be a singular VNode.");
}
}
return new VNode<T>(
VNodeFlags.UpdateContext,
null,
Expand Down

0 comments on commit 8c8f97f

Please sign in to comment.