Created
November 2, 2021 12:20
-
-
Save amatiasq/a2e0eea6ef2b2abed75f2832f8efc6cf to your computer and use it in GitHub Desktop.
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