Skip to main content

Function: mock()

Call Signature

mock<T>(clazz): T

Defined in: ts-mockito.ts:67

Creates a mock of the given class, abstract class, or generic class. Every method returns null/undefined until stubbed with when.

Type Parameters

T

T

Parameters

clazz

Function & object | ((...args) => T)

the class to mock

Returns

T

the mock; use it with when, verify and capture, and pass it to instance to get an object usable in the code under test

Example

const mockedFoo = mock(Foo);
when(mockedFoo.getBar(3)).thenReturn('three');
const foo = instance(mockedFoo);
console.log(foo.getBar(3)); // 'three'

Call Signature

mock<T>(clazz?): T

Defined in: ts-mockito.ts:80

Creates a mock of an interface (or other type with no runtime representation). The generic type parameter must be supplied explicitly since there's no class to infer it from.

Type Parameters

T

T

Parameters

clazz?

any

Returns

T

the mock; use it with when, verify and capture, and pass it to instance to get an object usable in the code under test

Example

const mockedFoo = mock<FooInterface>();
const foo = instance(mockedFoo);