Last active
November 25, 2016 05:03
-
-
Save johnwook/5d65824914bc1be3107de7c1ed620948 to your computer and use it in GitHub Desktop.
Why I like TypeScript — 1 Reliable Mocking with Interface
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
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