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
    '); }); });