From 45b80c0bed41f427c56a770b97d41040bfd70ef7 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sat, 27 Aug 2022 13:39:20 +0200 Subject: [PATCH] correct tests --- src/diff/index.js | 5 ++++- test/browser/refs.test.js | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/diff/index.js b/src/diff/index.js index 270e789cfb3..e518b8f35c8 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -477,6 +477,7 @@ function diffElementNodes( */ export function applyRef(ref, value, vnode) { try { + console.log('applying ref', value); if (typeof ref == 'function') ref(value); else ref.current = value; } catch (e) { @@ -497,7 +498,9 @@ export function unmount(vnode, parentVNode, skipRemove) { if (options.unmount) options.unmount(vnode); if ((r = vnode.ref)) { - if (!r.current || r.current === vnode._dom) applyRef(r, null, parentVNode); + if (!r.current || r.current === vnode._dom) { + applyRef(r, null, parentVNode); + } } if ((r = vnode._component) != null) { diff --git a/test/browser/refs.test.js b/test/browser/refs.test.js index 2472cdd22ac..59f5d9ec39c 100644 --- a/test/browser/refs.test.js +++ b/test/browser/refs.test.js @@ -509,7 +509,7 @@ describe('refs', () => { expect(ref.current).to.equal(scratch.firstChild.firstChild); }); - it('should properly call null for memoized components keyed', () => { + it.only('should properly call null for memoized components keyed', () => { const calls = []; const element =
calls.push(x)}>hey
; function App(props) { @@ -517,13 +517,16 @@ describe('refs', () => { } render(, scratch); - expect(calls[0]).to.equal(scratch.firstChild.firstChild); render(, scratch); - expect(calls[1]).to.equal(null); - expect(calls[2]).to.equal(scratch.firstChild.firstChild); render(, scratch); - expect(calls[3]).to.equal(null); - expect(calls[4]).to.equal(scratch.firstChild.firstChild); + expect(calls.length).to.equal(5); + expect(calls).to.deep.equal([ + scratch.firstChild.firstChild, + null, + scratch.firstChild.firstChild, + null, + scratch.firstChild.firstChild + ]); }); it('should properly call null for memoized components unkeyed', () => { @@ -534,12 +537,9 @@ describe('refs', () => { } render(, scratch); - expect(calls[0]).to.equal(scratch.firstChild.firstChild); render(, scratch); - expect(calls[1]).to.equal(null); - expect(calls[2]).to.equal(scratch.firstChild.firstChild); render(, scratch); - expect(calls[3]).to.equal(null); - expect(calls[4]).to.equal(scratch.firstChild.firstChild); + expect(calls.length).to.equal(1); + expect(calls[0]).to.equal(scratch.firstChild.firstChild); }); });