import { expect, test } from "vitest" import { combineLatestArray, combineLatestObject, computed, derived, mergeArray, signal, withLatestFrom, zip, } from "#Source/reactor/index.ts" test("combineLatestArray operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = derived(() => { return a.get() * 2 }) const d = computed(() => { return a.get() + b.get() + c.get() }) const combined = combineLatestArray({ target: [a, b, c, d] }) expect(combined.get()).toEqual([1, 2, 2, 5]) a.set(3) expect(combined.get()).toEqual([3, 2, 6, 11]) b.set(4) expect(combined.get()).toEqual([3, 4, 6, 13]) }) test("combineLatestObject operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = derived(() => { return a.get() * 2 }) const d = computed(() => { return a.get() + b.get() + c.get() }) const combined = combineLatestObject({ target: { a, b, c, d } }) expect(combined.get()).toEqual({ a: 1, b: 2, c: 2, d: 5 }) a.set(3) expect(combined.get()).toEqual({ a: 3, b: 2, c: 6, d: 11 }) b.set(4) expect(combined.get()).toEqual({ a: 3, b: 4, c: 6, d: 13 }) }) test("mergeArray operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = mergeArray({ target: [a, b] }) expect(c.get()).toBe(2) a.set(3) expect(c.get()).toBe(3) b.set(4) expect(c.get()).toBe(4) }) test("withLatestFrom operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = withLatestFrom({ target: a, other: b }) expect(c.get()).toEqual([1, 2]) a.set(3) expect(c.get()).toEqual([3, 2]) b.set(4) expect(c.get()).toEqual([3, 2]) a.set(5) expect(c.get()).toEqual([5, 4]) }) test("zip operator should work correctly", () => { const a = signal(() => 1) const b = signal(() => 2) const c = zip({ a, b }) expect(c.get()).toEqual([1, 2]) a.set(3) expect(c.get()).toEqual([1, 2]) b.set(4) expect(c.get()).toEqual([3, 4]) })