spy

← All adapters

spy<T>(): SpyAdapter<T>

Records all exchanges passing through it. Use as a destination, processor, or enricher to capture and assert on pipeline output.

import { spy } from '@routecraft/testing'

const spyAdapter = spy()

const route = craft()
  .id('my-route')
  .from(simple('payload'))
  .to(spyAdapter)

const t = await testContext().routes(route).build()
await t.test()

expect(spyAdapter.received).toHaveLength(1)
expect(spyAdapter.received[0].body).toBe('payload')
expect(spyAdapter.calls.send).toBe(1)

Properties:

FieldTypeDefaultRequiredDescription
receivedExchange[][]NoAll exchanges recorded
calls.sendnumber0NoNumber of times used as destination
calls.processnumber0NoNumber of times used as processor
calls.enrichnumber0NoNumber of times used as enricher

Methods:

MethodReturnsDescription
reset()voidClear all recorded data
lastReceived()ExchangeMost recent exchange
receivedBodies()unknown[]Array of just the body values

See Testing for full usage patterns.