Skip to content

Instantly share code, notes, and snippets.

@johnwook
Last active November 25, 2016 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnwook/5d65824914bc1be3107de7c1ed620948 to your computer and use it in GitHub Desktop.
Save johnwook/5d65824914bc1be3107de7c1ed620948 to your computer and use it in GitHub Desktop.
Why I like TypeScript — 1 Reliable Mocking with Interface
describe('sendSMS()', () => {
it('returns status code of smsClient.singleSend method', async () => {
// given
const verification = new Verification();
const mockSMSClient = jest.fn();
// which mocks real response from thir party request
const fakeSMSResponse = {
code: 0,
msg: 'dummy message',
};
mockSMSClient.mockReturnValue(Promise.resolve(fakeSMSResponse));
verification.SMSClient.singleSend = mockSMSClient;
// when
const result = await verification.sendSMS();
// then
expect(result).toBe(fakeSMSResponse.code);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment