This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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