Skip to content

Commit

Permalink
Add test for signals
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 12, 2024
1 parent 6476a09 commit 91f6188
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,11 @@ function diffElementNodes(
} else if (typeof newChildren === 'string') {
if (newChildren !== oldProps.children) {
// Unmount any previous children
if (oldVNode._children) {
while ((i = oldVNode._children.pop())) {
// Setting textContent on the dom element will unmount all DOM nodes
// of the previous children, so we don't need to remove DOM in this
// call to unmount
unmount(i, oldVNode, true);
}
while (oldVNode._children && (i = oldVNode._children.pop())) {
// Setting textContent on the dom element will unmount all DOM nodes
// of the previous children, so we don't need to remove DOM in this
// call to unmount
unmount(i, oldVNode, true);
}

// @ts-expect-error
Expand Down
13 changes: 12 additions & 1 deletion test/browser/components.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, render, Component, Fragment } from 'preact';
import { createElement, render, Component, Fragment, createRef } from 'preact';
import { setupRerender } from 'preact/test-utils';
import {
setupScratch,
Expand Down Expand Up @@ -2078,6 +2078,17 @@ describe('Components', () => {
expect(parentDom1.base).to.equalNode(scratch.firstChild);
});

it('should set c.base for a single text-node child', () => {
let ref = createRef();
const SignalValue = props => {
return props.text;
};
render(<SignalValue ref={ref} text="hello world" />, scratch);
console.log(ref.current);
expect(ref.current.base.nodeType).to.equal(3);
expect(ref.current.base.data).to.equal('hello world');
});

it('should not update sibling c.base if child component changes DOM nodes', () => {
let s1 = {},
s2 = {},
Expand Down

0 comments on commit 91f6188

Please sign in to comment.