Skip to content

Commit

Permalink
Add test for #620 (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Dec 6, 2024
1 parent 2d359bb commit c9c98e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/preact/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,38 @@ describe("@preact/signals", () => {
expect(scratch.textContent).to.equal("bar");
});

it('should not update signals that are "equal"', () => {
const count = signal(0);
const time = computed(() => (count.value < 2 ? count.value : "max"));
let renders = 0;
const Time = () => {
const value = time.value;
renders++;
return <p>{value}</p>;
};
render(<Time />, scratch);
expect(scratch.textContent).to.equal("0");
expect(renders).to.equal(1);

act(() => {
count.value++;
});
expect(scratch.textContent).to.equal("1");
expect(renders).to.equal(2);

act(() => {
count.value++;
});
expect(scratch.textContent).to.equal("max");
expect(renders).to.equal(3);

act(() => {
count.value++;
});
expect(scratch.textContent).to.equal("max");
expect(renders).to.equal(3);
});

it("should activate signal accessed in render", () => {
const sig = signal(null);

Expand Down

0 comments on commit c9c98e5

Please sign in to comment.