Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.