Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created November 2, 2021 12:20
Embed
What would you like to do?
import { mock, instance, when, verify, anything } from 'ts-mockito';
const mockedFoo: Foo = mock(Foo);
// stub method before execution
when(mockedFoo.getBar(3)).thenReturn('three');
// Getting instance from mock
const foo: Foo = instance(mockedFoo);
// Using instance in source code
foo.getBar(3);
foo.getBar(5);
// Explicit, readable verification
verify(mockedFoo.getBar(3)).called();
verify(mockedFoo.getBar(anything())).called();
// parameter validation
verify(mockedFoo.getBar(4)).never();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment