Skip to content

Commit

Permalink
Fix and Perfect test
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Nov 3, 2023
1 parent d2b6e8c commit 44b6b6a
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions packages/reactive/src/proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("proxy", () => {
const reactiveState = proxy(state);
const listener = vitest.fn();

reactiveState[LISTENERS].add({ callback: listener, mode: "async" });
reactiveState[LISTENERS].add(listener);
reactiveState.count = 10;

runMacroTask(() => {
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("proxy", () => {
const reactiveState = proxy(state);
const listener = vitest.fn();

reactiveState[LISTENERS].add({ callback: listener, mode: "async" });
reactiveState[LISTENERS].add(listener);
delete reactiveState.count;

runMacroTask(() => {
Expand All @@ -107,8 +107,8 @@ describe("proxy", () => {
const listener1 = vitest.fn();
const listener2 = vitest.fn();

reactiveState.nested[LISTENERS].add({ callback: listener1, mode: "async" });
reactiveState[LISTENERS].add({ callback: listener2, mode: "async" });
reactiveState.nested[LISTENERS].add(listener1);
reactiveState[LISTENERS].add(listener2);

reactiveState.nested.prop = 5;

Expand All @@ -118,6 +118,39 @@ describe("proxy", () => {
});
});

it("should be handled correctly deletion logic .", () => {
const state = { nested: { prop: 0 } };
const reactiveState = proxy(state);
const listener1 = vitest.fn();
const listener2 = vitest.fn();

reactiveState.nested[LISTENERS].add(listener1);
reactiveState[LISTENERS].add(listener2);

delete reactiveState.nested

runMacroTask(() => {
expect(listener1).not.toBeCalled();
expect(listener2).toHaveBeenCalledTimes(1);
});
});

it("should be handled correctly Use cached listeners.", () => {
const state = { nested: { prop: 0 } };
const reactiveState = proxy(state);
const listener1 = vitest.fn();

reactiveState.nested[LISTENERS].add(listener1);


reactiveState.nested = reactiveState.nested
reactiveState.nested.prop = 2 ;

runMacroTask(() => {
expect(listener1).toHaveBeenCalledTimes(1);
});
});

it("should not notify listeners when a property is not truly changed", () => {
const state = { count: 0 };
const reactiveState = proxy(state);
Expand Down

0 comments on commit 44b6b6a

Please sign in to comment.