Skip to content

fix(drivers): mock's failWhen predicate always receives index 0 on send() #113

Closed

Description

@productdevbook

What happens

mock({ failWhen }) is documented as "fail only the messages this predicate matches — for testing partial batch failures". In the send() path the index argument is hardcoded to 0, so an index-based predicate behaves differently depending on how the message was sent.

Reproduction

const seen: number[] = []
const driver = mock({ failWhen: (_m, i) => { seen.push(i); return false } })
const email = createEmail({ driver, defaults })
await email.send({ ...msg, subject: "1" })
await email.send({ ...msg, subject: "2" })
await email.send({ ...msg, subject: "3" })

Observed:

indices over 3 sends: [0,0,0]

So mock({ failWhen: (m, i) => i === 1 }) fails the second message of a sendBatch and never fires for send().

Why it matters

This is the driver people reach for when writing tests, and a test helper that quietly does nothing is worse than one that is missing — the test passes and proves nothing. The asymmetry is invisible: the same predicate behaves differently depending on the batch size the core happened to choose.

Where

src/drivers/mock.ts:76 — opts.failWhen?.(msg, 0) in send, versus the real index in sendBatch at line 89.

Suggested fix

Either give send() a per-instance running counter so the index keeps meaning "which message", or drop the index parameter and let predicates match on the message. Matching on the message is the honest option, since a single send() has no meaningful position.

Activity

  1. productdevbook commented on Sep 1, 2026

    @productdevbook
    OwnerAuthor

    Fixed in 9733a8f (#129), with a regression test. Suite went from 190 tests to 269.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions