TypeMoq is a mocking library for TypeScript that provides a fluent interface for creating and managing mock objects. It is particularly useful for writing unit tests for TypeScript applications.
In this example, we create a mock object for an interface called `MyInterface`. The `Mock.ofType` method takes the interface as a type parameter, and returns a mock object that implements the interface.
In this example, we set up the `myMethod` method of the mock object to return the string 'hello world'. The `setup` method takes a lambda expression that represents the method call, and returns a `MethodCallReturn` object that can be used to set up the method return value.
3. Verifying a mock method was called:
mockObject.verify(x => x.myMethod());
In this example, we verify that the `myMethod` method of the mock object was called at least once. The `verify` method takes a lambda expression that represents the method call, and throws an exception if the method was not called.
TypeMoq is a package library for TypeScript that can be installed using npm. The package name is `typemoq`, and it can be installed with the following command:
npm install typemoq --save-dev
TypeScript Mock - 30 examples found. These are the top rated real world TypeScript examples of typemoq.Mock extracted from open source projects. You can rate examples to help us improve the quality of examples.