import { describe, expect, it } from 'vitest'
import { computed, ref, watch } from 'vue'

describe('sync watcher order on computed', () => {
  it('triggers sync watchers in definition order (FIFO)', () => {
    const n = ref(0)
    const compN = computed(() => n.value)
    const order: number[] = []
    for (let i = 0; i < 5; i++) {
      const idx = i
      watch(
        compN,
        () => {
          order.push(idx)
        },
        { flush: 'sync' },
      )
    }
    n.value++
    expect(order).toEqual([0, 1, 2, 3, 4])
  })
})
