Times Api - slavik57/moqjs GitHub Wiki
Verify property getters/setters or functions
Verification can be done using the matching arguments: Matching arguments API
var foo = new FooClass();
var mole = new Mole(foo);
// Verify the function was called at least once and never with 2
var result1 = mole.verify(_ => _.doSomething(It.isAny(Object)));
var result2 = mole.verify(_ => _.doSomething(It.isAny(2)), Times.exact(0));
// Verify the private function was called at least once and never with 2
var result1 = mole.verifyPrivate('_doSomething', [It.isAny(Object)]);
var result2 = mole.verifyPrivate('_doSomething', [It.isAny(2)], Times.exact(0));
Verifying the calls can be done with or without Times class
var foo = new FooClass();
var mole = new Mole(foo);
// Verify the function was called
var result = mole.verify(_ => _.doSomething());
// Verify the function was called lessThan 2 times (0 or 1)
var result = mole.verify(_ => _.doSomething(), Times.lessThan(2));
// Verify the function was called atMost 2 times (0 or 1 or 2)
var result = mole.verify(_ => _.doSomething(), Times.atMost(2));
// Verify the function was called exactly 2 times
var result = mole.verify(_ => _.doSomething(), Times.exact(2));
// Verify the function was called atLeast 2 times (2 or 3 or more)
var result = mole.verify(_ => _.doSomething(), Times.atLeast(2));
// Verify the function was called moreThan 2 times (3 or more)
var result = mole.verify(_ => _.doSomething(), Times.moreThan(2));
// Verify the function was called between 2 and 4 times (2 or 3 or 4)
var result = mole.verify(_ => _.doSomething(), Times.between(2, 4));