From 9ec4982c970a2bf03ae807f802123f738416fbd6 Mon Sep 17 00:00:00 2001 From: "a.rubtsov" Date: Fri, 30 Dec 2016 10:30:25 +0300 Subject: [PATCH] fix(normalization): issue-648, remove props.key and props.ref --- src/core/__tests__/normalizeProps.spec.tsx | 39 ++++++++++++++++++++++ src/core/normalization.ts | 5 ++- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/core/__tests__/normalizeProps.spec.tsx diff --git a/src/core/__tests__/normalizeProps.spec.tsx b/src/core/__tests__/normalizeProps.spec.tsx new file mode 100644 index 000000000..cafb3bee3 --- /dev/null +++ b/src/core/__tests__/normalizeProps.spec.tsx @@ -0,0 +1,39 @@ +import { expect } from 'chai'; +import { normalize } from '../normalization'; +import { VNode } from '../structures'; + +describe('normalizeProps', () => { + it('should delete ref from props', () => { + const vNode: VNode = { + children: null, + dom: null, + events: null, + flags: 0, + key: null, + props: { ref: () => {} }, + ref: null, + type: null + }; + + normalize(vNode); + + expect(vNode.props).to.not.have.property('ref'); + }); + + it('should delete key from props', () => { + const vNode: VNode = { + children: null, + dom: null, + events: null, + flags: 0, + key: null, + props: { key: 'key' }, + ref: null, + type: null + }; + + normalize(vNode); + + expect(vNode.props).to.not.have.property('key'); + }); +}); diff --git a/src/core/normalization.ts b/src/core/normalization.ts index 457629530..73e6e3d4e 100644 --- a/src/core/normalization.ts +++ b/src/core/normalization.ts @@ -88,16 +88,15 @@ function normalizeProps(vNode: VNode, props: Props, children: InfernoChildren) { vNode.children = props.children; } if (props.ref) { + vNode.ref = props.ref; delete props.ref; } - if (props.key) { - delete props.key; - } if (props.events) { vNode.events = props.events; } if (!isNullOrUndef(props.key)) { vNode.key = props.key; + delete props.key; } }