Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Should process an error GET request with an error message', done => {
superagent.__setMockError(
new Error('There is a problem in your request')
);
var HttpManager = require('../src/http-manager');
var request = Request.builder()
.withHost('such.api.wow')
.withPort(1337)
.withScheme('http')
.build();
HttpManager.get(request, function(errorObject) {
expect(errorObject).toBeInstanceOf(Error);
expect(errorObject.message).toBe('There is a problem in your request');
done();
});
});
beforeEach(() => {
Request.__setMockResponse({
status() {
return 500;
},
ok() {
return false;
},
body: {
message_type: 'error'
}
});
Request.__setMockError({
message: 'Unsuccessful HTTP response'
});
});
afterEach(() => {
Request.__setMockError(undefined);
});
beforeEach(() => {
Request.__setMockResponse(response);
Request.__setMockError(error);
jest.useFakeTimers();
});