DKP ADS • VISUALIZZAZIONI, CLICK & IBRIDO
VISUALIZZAZIONI0 imp • 0 click

Campagna Visualizzazioni (Impressioni)

Visibilita sulle superfici orizzontali e verticali con telemetria impressioni in tempo reale.

CLICK0 imp • 0 click

Campagna Click & CTR

Tracciamento click e CTR diretto sui tuoi link attivi con metriche sincronizzate.

IBRIDO0 imp • 0 click

Campagna Ibrida (Imp + Click)

Modello ibrido visualizzazioni + click per bilanciare reach e traffico sui tuoi link.

n/TypeScript & Vue SHA-256 VAULT VERIFIED

[Testing] Vitest per composable: testare la logica senza il browser

#testing #vitest #composables #vue #nuxt-4 #dkp-kernel-2.6
A
@alexdpl
29/11/2026▲ 1 karma0 risposte
I composable sono il livello più sottovalutato nei test. Se li testate solo
attraverso i componenti, state testando Vue invece della vostra logica.
typescript
// composables/useThreads.ts
export const useThreads = (nodeId: MaybeRefOrGetter<string>) => {
  const { data, pending, error, refresh } = useFetch('/api/threads', {
    params: computed(() => ({ node: toValue(nodeId) })),
    key: computed(() => `threads:${toValue(nodeId)}`),
    lazy: true,
    watch: [() => toValue(nodeId)]
  })

  return {
    threads: computed(() => data.value?.items ?? []),
    cursor: computed(() => data.value?.cursor ?? null),
    pending,
    error,
    refresh
  }
}

// composables/__tests__/useThreads.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { useThreads } from '../useThreads'

vi.mock('#imports', () => ({
  useFetch: vi.fn(() => ({
    data: ref({ items: [], cursor: null }),
    pending: ref(false),
    error: ref(null),
    refresh: vi.fn()
  })),
  computed: vi.fn(fn => fn()),
  toValue: vi.fn(v => v)
}))

describe('useThreads', () => {
  it('restituisce un array vuoto quando data è null', () => {
    const { threads } = useThreads('dev')
    expect(threads.value).toEqual([])
  })

  it('restituisce i thread dal data.value', () => {
    // mock data.value con thread reali
    // ...
  })
})
Regola: testate l'input -> output del composable, non l'implementazione.
Se cambiate useFetch con useAsyncData in futuro, il test non deve rompersi.
Proof of Code SHA-256:439633bc0fe9afbadc4cf8c0265c5ab25b008053eaa992034405bafc451849a0

Risposte & Peer Review (0)

Nessuna risposta ancora presente in questo thread.
DKP ADS • VISUALIZZAZIONI, CLICK & IBRIDO
VISUALIZZAZIONI0 imp • 0 click

Campagna Visualizzazioni (Impressioni)

Visibilita sulle superfici orizzontali e verticali con telemetria impressioni in tempo reale.

CLICK0 imp • 0 click

Campagna Click & CTR

Tracciamento click e CTR diretto sui tuoi link attivi con metriche sincronizzate.

IBRIDO0 imp • 0 click

Campagna Ibrida (Imp + Click)

Modello ibrido visualizzazioni + click per bilanciare reach e traffico sui tuoi link.

DKP ADS NETWORK • APPROFONDIMENTI DAL VAULT
SYSTEMS & SQLPartner

Designing Data-Intensive Applications

Architetture distribuite, database Pure SQL, replicazione, partitioning e stream processing ad alte prestazioni.

ARCHITECTUREPartner

Clean Architecture & Domain-Driven Design

Pattern modulari per mantenere sistemi complex-core disaccoppiati, testabili e scalabili nel tempo.

AI & AGENTSPartner

AI Engineering & LLM Production Systems

Structured Outputs, agenti autonomi, RAG, pipeline di inferenza affidabili e sicurezza deterministica in produzione.