import { expect, test } from "vitest" import { getValuesInArray, getValuesInObject, signal, subscribe } from "#Source/reactor/index.ts" test("subscribe operator should skip first value", () => { const a = signal(() => 0) let consumerRunTimes = 0 const unsubscribe = subscribe({ target: a, subscriber: (value) => { consumerRunTimes = consumerRunTimes + 1 expect(value).toBe(1) }, }) a.set(1) expect(consumerRunTimes).toBe(1) unsubscribe() a.set(2) expect(consumerRunTimes).toBe(1) }) test("getValuesInArray operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = signal(() => 3) const values = getValuesInArray({ target: [a, b, c] }) expect(values).toEqual([1, 2, 3]) a.set(4) b.set(5) c.set(6) const newValues = getValuesInArray({ target: [a, b, c] }) expect(newValues).toEqual([4, 5, 6]) }) test("getValuesInObject operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = signal(() => 3) const values = getValuesInObject({ target: { a, b, c } }) expect(values).toEqual({ a: 1, b: 2, c: 3 }) a.set(4) b.set(5) c.set(6) const newValues = getValuesInObject({ target: { a, b, c } }) expect(newValues).toEqual({ a: 4, b: 5, c: 6 }) })