Readonly
optionsReturns options object
Readonly
trackerReturns the tracker object that responsible for storing history of interactions with the mocked object.
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]].
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 internal core of Mock class.