Skip to content

Commit

Permalink
Add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Oct 13, 2022
1 parent e968a5a commit 004d25b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,25 @@ describe('hydrate()', () => {

it('should skip comment nodes between dom nodes', () => {
scratch.innerHTML = '<p><i>0</i><!-- c --><b>1</b></p>';
clearLog();
const records = [];
const obs = new MutationObserver(r => {
records.push(...r);
});
obs.observe(scratch, { childList: true, subtree: true });
hydrate(
<p>
<i>0</i>
<b>1</b>
</p>,
scratch
);
records.push(...obs.takeRecords());
obs.disconnect();
expect(scratch.innerHTML).to.equal('<p><i>0</i><b>1</b></p>');
// Expect only one mutation: removing the comment.
expect(records.length).to.equal(1);
expect(getLog()).to.deep.equal(['Comment.remove()']);
});

it('should reuse existing DOM when given components', () => {
Expand Down Expand Up @@ -460,7 +471,18 @@ describe('hydrate()', () => {

it('should skip comment nodes', () => {
scratch.innerHTML = '<p>hello <!-- c -->foo</p>';
clearLog();
const records = [];
const obs = new MutationObserver(r => {
records.push(...r);
});
obs.observe(scratch, { childList: true, subtree: true });
hydrate(<p>hello {'foo'}</p>, scratch);
records.push(...obs.takeRecords());
obs.disconnect();
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
// Expect only one mutation: removing the comment.
expect(records.length).to.equal(1);
expect(getLog()).to.deep.equal(['Comment.remove()']);
});
});

0 comments on commit 004d25b

Please sign in to comment.