ruvnet/ruflo · error
Mock was called with unexpected arguments: ${JSON.stringify(
Error message
Mock was called with unexpected arguments: ${JSON.stringify(call)}\nAllowed: ${JSON.stringify(allowedCalls)} What it means
assertOnlyCalledWithAllowed() compares every recorded call of a mock against an allowlist using JSON.stringify equality; any call that does not exactly match an allowed argument array throws, printing the offending call and the whole allowlist. Equality is structural and order-sensitive, so argument order and extra arguments matter.
Source
Thrown at v3/@claude-flow/testing/src/helpers/assertion-helpers.ts:352
/**
* Assert that a mock was only called with allowed arguments
*
* @example
* assertOnlyCalledWithAllowed(mockFn, [['valid1'], ['valid2']]);
*/
export function assertOnlyCalledWithAllowed(
mock: Mock,
allowedCalls: unknown[][]
): void {
const calls = mock.mock.calls;
for (const call of calls) {
const isAllowed = allowedCalls.some(
allowed => JSON.stringify(call) === JSON.stringify(allowed)
);
if (!isAllowed) {
throw new Error(
`Mock was called with unexpected arguments: ${JSON.stringify(call)}\n` +
`Allowed: ${JSON.stringify(allowedCalls)}`
);
}
}
}
/**
* Assert that an array contains elements in partial order
*
* @example
* assertPartialOrder(events, [
* { type: 'Start' },
* { type: 'Process' },
* { type: 'End' },
* ]);
*/
export function assertPartialOrder<T>(View on GitHub (pinned to fa13ee4ad6)
Solutions
- Print mock.mock.calls first and build the allowlist from actual legitimate invocations
- Update the test to cover the new legitimate call signature when a refactor added arguments
- For unstable serializations (Date, NaN, class instances), match on extracted fields instead of raw JSON equality
Example fix
// before
assertOnlyCalledWithAllowed(mockSave, [['user-1']]); // throws if code calls save('user-1', { upsert: true })
// after
assertOnlyCalledWithAllowed(mockSave, [['user-1'], ['user-1', { upsert: true }]]); Defensive patterns
Strategy: validation
Validate before calling
// Preview recorded calls before asserting
const calls = mock.mock.calls;
console.log('recorded calls:', JSON.stringify(calls, null, 2));
assertOnlyCalledWithAllowed(mock, allowedCalls); Type guard
function allCallsAllowed(mock: Mock, allowedCalls: unknown[][]): boolean {
return mock.mock.calls.every(call =>
allowedCalls.some(a => JSON.stringify(call) === JSON.stringify(a))
);
} Prevention
- Derive allowedCalls from a recording of one known-good run instead of hand-writing them
- Type collaborator signatures so added arguments surface as compile errors
- Avoid JSON-equality assertions on values with unstable serialization such as Date or undefined
When it happens
Trigger: The code under test invokes the mock with an extra argument, different order, or a value not in allowedCalls; optional parameters materializing as undefined changing the JSON; Dates or floats serializing differently than expected.
Common situations: Refactors adding a new parameter to a collaborator call; allowlists written from memory instead of from mock.mock.calls; non-JSON-safe values in arguments.
Related errors
- Invalid domain object: ${result.errors?.join(', ')}
- Expected to find ${JSON.stringify(expected)} after index ${l
- Item at index ${i} failed predicate: ${JSON.stringify(items[
- Item at index ${i} passed predicate but should not have: ${J
- Invalid state transition from '${from}' to '${to}'. Allowed
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/f8e90275a0552c0d.
Report an issue: GitHub.