Skip to content

Commit

Permalink
Add conditional components test case
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Oct 25, 2022
1 parent b3a1e5a commit 8cdab51
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hooks/test/browser/useId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,29 @@ describe('useId', () => {
const res2 = rts(<App />);
expect(res1).to.equal(res2);
});

it('should work with conditional components', () => {
function Foo() {
const id = useId();
return <p>{id}</p>;
}
function Bar() {
const id = useId();
return <p>{id}</p>;
}

let update;
function App() {
const [v, setV] = useState(false);
update = setV;
return <div>{!v ? <Foo /> : <Bar />}</div>;
}

render(<App />, scratch);
const first = scratch.innerHTML;

update(v => !v);
rerender();
expect(first).not.to.equal(scratch.innerHTML);
});
});

0 comments on commit 8cdab51

Please sign in to comment.