Skip to content

Commit

Permalink
add tests from #3696
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 26, 2022
1 parent fbe464c commit a1dca7f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/browser/refs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,69 @@ describe('refs', () => {
expect(el.innerHTML).to.be.equal('Bar');
expect(ref.current.innerHTML).to.be.equal('Foo');
});

it.skip('should not remove refs for memoized components keyed', () => {
const ref = createRef();
const element = <div ref={ref}>hey</div>;
function App(props) {
return <div key={props.count}>{element}</div>;
}

render(<App count={0} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
render(<App count={1} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
render(<App count={2} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
});

it('should not remove refs for memoized components unkeyed', () => {
const ref = createRef();
const element = <div ref={ref}>hey</div>;
function App(props) {
return <div>{element}</div>;
}

render(<App count={0} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
render(<App count={1} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
render(<App count={2} />, scratch);
expect(ref.current).to.equal(scratch.firstChild.firstChild);
});

// TODO
it.skip('should properly call null for memoized components keyed', () => {
const calls = [];
const element = <div ref={x => calls.push(x)}>hey</div>;
function App(props) {
return <div key={props.count}>{element}</div>;
}

render(<App count={0} />, scratch);
render(<App count={1} />, scratch);
render(<App count={2} />, scratch);
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', () => {
const calls = [];
const element = <div ref={x => calls.push(x)}>hey</div>;
function App(props) {
return <div>{element}</div>;
}

render(<App count={0} />, scratch);
render(<App count={1} />, scratch);
render(<App count={2} />, scratch);
expect(calls.length).to.equal(1);
expect(calls[0]).to.equal(scratch.firstChild.firstChild);
});
});

0 comments on commit a1dca7f

Please sign in to comment.