You can name the mock. The name will be displayed with any relative output, so you can easily distinct output of several mocks. On the mocked object you can find this name at 'mockName' property of the [[Handler]].
Returns options object
Static
optionsThe default mock options that would appnpmly to all instantiating Mock objects. By default it sets target as a function, injectorConfig as instance of DefaultInjectorConfig and name as undefined. If an options are passed as constructor parameter constructor they will override the default options.
The default mock options that would applied to all instantiating Mock objects. If an options are passed as constructor parameter they will override the default options.
Experimental
Set the prototype of the mocked object.
class PrototypeClass {}
const mock = new Mock<{}>();
const object = mock.object();
Object.setPrototypeOf(object, PrototypeClass.prototype);
expect(object instanceof PrototypeClass).toBe(true);
Optional
prototype: anyRetrieves an instance from the injector based on the provided token.
The instance from the injector if defined, otherwise null.
Defines a configuration for particular interaction with the mocked object.
// a function invoke with 1 as parameter
.setup(instance => instance(1))
// apply function invoke on a function with null as the first parameter and a placeholder for the second parameter
.setup(instance => instance.apply(null, It.IsAny()))
// accessing to a property
.setup(instance => instance.property)
//accessing to a named function with name 'test' of an object and the first parameter is 1
.setup(instance => It.Is((expression: NamedMethodExpression) => {
return expression.name === 'test' && expression.args[0] === 1
}))
//setting propertyA to value of 'a'
.setup(instance => {instance.propertyA = 'a'})
PresetBuilder config interface for the provided expression.
Asserts expected interactions with the mocked object.
Expected expression
The default value is ()
Generated using TypeDoc
The default implementation of IMock interface.