Created
June 18, 2022 22:04
-
-
Save spencerfeng/20ffc0ee7f32a79a39d70bf0543cb0b6 to your computer and use it in GitHub Desktop.
Sudo Test For Edward
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
const mockedRequest = jest.fn() | |
const callback1 = mockedRequest.mock.calls[0][1] | |
const callback2 = mockedRequest.mock.calls[1][1] | |
const callback3 = mockedRequest.mock.calls[2][1] | |
it('should return and send error if count is 3', () => { | |
const mockedSend = jest.fn() | |
const mockedRes = { | |
send: mockedSend, | |
}; | |
callAWSapi(url, mockedRes, 3) | |
expect(mockedSend).toHaveBeenCalledTimes(1); | |
expect(mockedSend).toHaveBeenCalledWith({error: 'Internal System Error'}) | |
}) | |
it("should send response body if count is 1 and request is successful", () => { | |
const mockedSend = jest.fn(); | |
const mockedRes = { | |
send: mockedSend, | |
}; | |
callAWSapi(url, mockedRes, 1); | |
const successfulResponse = { | |
statusCode: 200, | |
body: { | |
key: 'test' | |
} | |
} | |
callback1(undefined, successfulResponse, undefined); | |
expect(mockedSend).toHaveBeenCalledTimes(1); | |
expect(mockedSend).toHaveBeenCalledWith(JSON.stringify(successfulResponse.body)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment