From 30b577138dda685f65a8529be1866afa6e321845 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 4 Oct 2016 11:50:26 +0200 Subject: Squashed 'thirdparty/preact/' content from commit b2d90cc git-subtree-dir: thirdparty/preact git-subtree-split: b2d90cc116f1d1998f7a7c98dc6986bf4c1841f4 --- test/browser/keys.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 test/browser/keys.js (limited to 'test/browser/keys.js') diff --git a/test/browser/keys.js b/test/browser/keys.js new file mode 100644 index 000000000..e0a6b9ae8 --- /dev/null +++ b/test/browser/keys.js @@ -0,0 +1,85 @@ +import { h, Component, render } from '../../src/preact'; +/** @jsx h */ + +describe('keys', () => { + let scratch; + + before( () => { + scratch = document.createElement('div'); + (document.body || document.documentElement).appendChild(scratch); + }); + + beforeEach( () => { + scratch.innerHTML = ''; + }); + + after( () => { + scratch.parentNode.removeChild(scratch); + scratch = null; + }); + + // See developit/preact-compat#21 + it('should remove orphaned keyed nodes', () => { + let root = render(( +
+
1
+
  • a
  • +
    + ), scratch); + + root = render(( +
    +
    2
    +
  • b
  • +
    + ), scratch, root); + + expect(scratch.innerHTML).to.equal('
    2
  • b
  • '); + }); + + it('should set VNode#key property', () => { + expect(
    ).to.have.property('key').that.is.empty; + expect(
    ).to.have.property('key').that.is.empty; + expect(
    ).to.have.property('key', '1'); + }); + + it('should remove keyed nodes (#232)', () => { + class App extends Component { + componentDidMount() { + setTimeout(() => this.setState({opened: true,loading: true}), 10); + setTimeout(() => this.setState({opened: true,loading: false}), 20); + } + + render({ opened, loading }) { + return ( + +
    This div needs to be here for this to break
    + { opened && !loading &&
    {[]}
    } +
    + ); + } + } + + class BusyIndicator extends Component { + render({ children, busy }) { + return
    + { children && children.length ? children :
    } +
    +
    indicator
    +
    indicator
    +
    indicator
    +
    +
    ; + } + } + + let root; + + root = render(, scratch, root); + root = render(, scratch, root); + root = render(, scratch, root); + + let html = String(root.innerHTML).replace(/ class=""/g, ''); + expect(html).to.equal('
    This div needs to be here for this to break
    indicator
    indicator
    indicator
    '); + }); +}); -- cgit v1.2.3