diff --git a/src/reactivity.ts b/src/reactivity.ts index e507d048..1f3660e6 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -130,7 +130,7 @@ const reactiveCache = new WeakMap>(); * reactive has changed * @returns a proxy that tracks changes to it */ -export function reactive(target: T, callback: Callback): Reactive { +export function reactive(target: T, callback: Callback = () => {}): Reactive { if (!canBeMadeReactive(target)) { throw new Error(`Cannot make the given value reactive`); } diff --git a/tests/reactivity.test.ts b/tests/reactivity.test.ts index 87c1a95b..235bd96f 100644 --- a/tests/reactivity.test.ts +++ b/tests/reactivity.test.ts @@ -60,6 +60,13 @@ describe("Reactivity", () => { expect(Array.isArray(state)).toBe(true); }); + test("work if there are no callback given", () => { + const state = reactive({ a: 1 }); + expect(state.a).toBe(1); + state.a = 2; + expect(state.a).toBe(2); + }); + test("Throw error if value is not proxifiable", () => { expect(() => createReactive(1)).toThrow("Cannot make the given value reactive"); });