79651783

Date: 2025-06-03 18:55:09
Score: 2.5
Natty:
Report link

Naturally, right after I make a StackOverflow question I figure it out!

The answer is to call .persist() after the .reply call:


    agent
        .get('https://stackoverflow.com')
        .intercept({
        path: '/notarealendpoint',
        method: 'GET',
    })
        .reply(200, "foo")
        // this is new
        .persist();

See https://github.com/nodejs/undici/blob/main/types/mock-interceptor.d.ts#L10.

There's also a .times function if you only want the mock to persist N times.

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Blacklisted phrase (1): stackoverflow
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: vanchagreen