It Api - slavik57/moqjs GitHub Wiki
Matching the function calls
Usefull for setup and the verify methods.
var foo = new FooClass();
var mole = new Mole(foo);
// Match specific object
var obj = {};
mole.setup(_ => _.doSomething(obj))...
mole.verify(_ => _.doSomething(obj))...
// Match specific string
mole.setup(_ => _.doSomething('some string'))...
mole.verify(_ => _.doSomething('some string'))...
// Match specific number
mole.setup(_ => _.doSomething(1))...
mole.verify(_ => _.doSomething(1))...
Matching can be done with the 'It' classes
var foo = new FooClass();
var mole = new Mole(foo);
// Match by type
mole.setup(_ => _.doSomething(It.isAny(String))...
mole.verify(_ => _.doSomething(It.isAny(Number))...
// Match by numeric range
mole.setup(_ => _.doSomething(It.isInRange(1, 3))...
mole.verify(_ => _.doSomething(It.isInRange(1, 3))...
// Match by regular expression
var reg = new RegExp(...);
mole.setup(_ => _.doSomething(It.isRegExp(reg))...
mole.verify(_ => _.doSomething(It.isRegExp(reg))...
// Custom matchers
var matchingFunction = function (arg) {
return arg === null || arg === 2;
};
mole.setup(_ => _.doSomething(It.is(matchingFunction))...
mole.verify(_ => _.doSomething(It.is(matchingFunction))...