nodejs/node · error · InvalidArgumentError
UND_ERR_INVALID_ARG
UND_ERR_INVALID_ARG
Error message
waitInMs must be a valid integer > 0
What it means
Thrown by MockScope.delay when waitInMs is not a number, not an integer, or not greater than zero. delay sets a response latency on a mock dispatch; fractional, zero, or negative durations are rejected so the delay timer is always well-defined.
Source
Thrown at deps/undici/src/lib/mock/mock-interceptor.js:34
types: {
isPromise
}
} = require('node:util')
/**
* Defines the scope API for an interceptor reply
*/
class MockScope {
constructor (mockDispatch) {
this[kMockDispatch] = mockDispatch
}
/**
* Delay a reply by a set amount in ms.
*/
delay (waitInMs) {
if (typeof waitInMs !== 'number' || !Number.isInteger(waitInMs) || waitInMs <= 0) {
throw new InvalidArgumentError('waitInMs must be a valid integer > 0')
}
this[kMockDispatch].delay = waitInMs
return this
}
/**
* For a defined reply, never mark as consumed.
*/
persist () {
this[kMockDispatch].persist = true
return this
}
/**
* Allow one to define a reply for a set amount of matching requests.
*/
times (repeatTimes) {View on GitHub (pinned to 1b2de5e052)
Solutions
- Pass a positive integer of milliseconds: delay(500).
- Omit delay() entirely when no delay is desired.
- Coerce and clamp config values: delay(Math.max(1, Math.floor(config.delay))).
Example fix
// before intercept.reply(200).delay(config.timeout) intercept.reply(200).delay(0) // after intercept.reply(200).delay(Math.max(1, Number(config.timeout))) intercept.reply(200) // no delay needed
Defensive patterns
Strategy: validation
Validate before calling
function safeDelay(scope, ms) {
if (typeof ms !== 'number' || !Number.isInteger(ms) || ms <= 0) {
throw new TypeError('delay expects a positive integer ms');
}
return scope.delay(ms);
} Type guard
function isPositiveIntegerMs(v) {
return typeof v === 'number' && Number.isInteger(v) && v > 0;
} Prevention
- Omit delay() entirely when no delay is needed.
- Coerce config strings with Number() and clamp with Math.max(1, ...).
- Never pass 0 — omit the call instead.
When it happens
Trigger: Calling interceptor.reply(200).delay(0), delay(-100), delay(1.5), delay('500'), or delay(undefined). Also delay() with no argument (undefined).
Common situations: Passing a delay from a config file as a string, using 0 intending 'no delay' (use omit instead), or computing a delay that can go non-positive.
Related errors
- expected ${name} to be an array or undefined, got ${typeof o
- expected ${name}[${i}] to be a string or RegExp, got ${typeo
- expected type of opts to be an Object, got ${opts === null ?
- expected opts.cacheByDefault to be number or undefined, got
- expected opts.type to be shared, private, or undefined, got
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/693643a22117b822.
Report an issue: GitHub.