Skip to content

Commit b22b277

Browse files
author
Sepand Parhami
committed
Add test for patching externally rendered DOM where a key moves up in the DOM on the first patch.
1 parent a3ae6ed commit b22b277

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.babelrc

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"transform-es2015-arrow-functions",
55
"transform-es2015-block-scoping",
66
"transform-es2015-computed-properties",
7+
"transform-es2015-template-literals"
78
]
89
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
"babel": "^6.5.2",
2626
"babel-plugin-check-es2015-constants": "^6.3.13",
2727
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
28+
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
2829
"babel-plugin-transform-es2015-computed-properties": "^6.5.2",
30+
"babel-plugin-transform-es2015-template-literals": "^6.6.5",
2931
"babel-plugin-transform-inline-environment-variables": "^6.5.0",
30-
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
3132
"chai": "^3.0.0",
3233
"del": "^2.0.2",
3334
"gulp": "^3.9.0",

test/functional/keyed_items.js

+17
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,22 @@ describe('rendering with keys', () => {
157157
patch(container, render, 'span');
158158
}).to.throw('Was expecting node with key "key" to be a span, not a div.');
159159
});
160+
161+
it('should preserve nodes already in the DOM', () => {
162+
function render() {
163+
elementVoid('div', 'key');
164+
elementVoid('div');
165+
}
166+
167+
container.innerHTML = `
168+
<div></div>
169+
<div key="key"><div>
170+
`;
171+
172+
const keyedDiv = container.lastChild;
173+
patch(container, render);
174+
175+
expect(container.firstChild).to.equal(keyedDiv);
176+
});
160177
});
161178

0 commit comments

Comments
 (0)