How spies work in mm
masterWhen a mocked property is a function, mm automatically attaches spy capabilities to it. Every time the function is called, mm updates the following properties on the function object:
.called: The number of times the function was called..calledArguments: An array of all arguments passed in every call..lastCalledArguments: The arguments from the most recent call.
If you only need to track calls without changing the implementation, use mm.spy(target, 'propertyName').
import { mm } from 'mm';
const target = {
async add(a, b) {
return a + b;
},
};
mm.data(target, 'add', 3);
assert.equal(await target.add(1, 1), 3);
assert.equal(target.add.called, 1);
assert.deepEqual(target.add.calledArguments, [[ 1, 1 ]]);
assert.deepEqual(target.add.lastCalledArguments, [ 1, 1 ]);