From b943cd10b55cd9d3217d53b65f94350e63662d3d Mon Sep 17 00:00:00 2001 From: David Johnson Date: Wed, 31 Jul 2019 11:41:15 -0400 Subject: [PATCH] Add case for prepending keys. --- tests/diff.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/diff.test.js b/tests/diff.test.js index e0e602ff..66493e57 100644 --- a/tests/diff.test.js +++ b/tests/diff.test.js @@ -553,6 +553,23 @@ test('Should execute left-hand side happy path key-window diffing case', () => { expect(currentNode.domRef.childNodes).toEqual(newNode.domRef.childNodes); }); +test('Should diff keys properly when keys are prepended', () => { + var document = new jsdom.JSDOM().window.document; + var body = document.body; + var destroy = 0; + var currentNode = + vnode('div', [vnodeKeyed('div', '1')], {}, {}, "html", null, null, null, "key-1"); + window['diff'](null, currentNode, body, document) + var newNode = + vnode('div', [vnodeKeyed('div', '2'), vnodeKeyed('div', '1')], {}, {}, "html", null, null, null, "key-1"); + window['diff'](currentNode, newNode, body, document) + expect(newNode.children.length).toBe(2); + expect(newNode.children.length).toBe(currentNode.children.length); + expect(currentNode.children).toEqual(newNode.children); + expect(currentNode.domRef.children).toEqual(newNode.domRef.children); + expect(currentNode.domRef.childNodes).toEqual(newNode.domRef.childNodes); +}); + test('Should execute right-hand side happy path key-window diffing case', () => { var document = new jsdom.JSDOM().window.document; var body = document.body;