Try Mockttp (disclaimer: I'm the maintainer of Mockttp).
Mockttp gives you a real local HTTP server & proxy that you can easily configure & use for testing, for exactly these kind of cases.
You can either make requests to Mockttp directly, using a localhost URL, or keep making requests to google.com but use Mockttp as a proxy, and then configure whatever responses (or failed connections/timeouts) you'd like to simulate.
There's some examples in the README that show exactly what you're looking for: https://www.npmjs.com/package/mockttp#get-testing. In your specific case, I'd try something like:
const makeRequest = require("./your-code");
const mockServer = require("mockttp").getLocal();
describe("makeRequest", () => {
beforeEach(() => mockServer.start());
afterEach(() => mockServer.stop());
it("resolves happily for successful requests", () => {
await mockServer.get("http://google.com").thenReply(200, "A mocked response");
// Here: configure your code to use mockServer.url as a proxy
let result = await makeRequest();
expect(response).to.equal('Connected to google');
});
it("rejects failed requests with an error", () => {
await mockServer.get("http://google.com").thenReply(500, "An error!");
// Here: configure your code to use mockServer.url as a proxy
let result = makeRequest();
expect(response).to.be.rejectedWith('Failed to connect to Google');
});
});
Configuring the proxy will depend on the libraries you're using, but for http.get https://www.npmjs.com/package/global-tunnel should do it, or you can pass a { proxy: mockServer.url } option to the http.get call directly. Or of course you could make the http://google.com URL configurable, set that to mockServer.url, and mock / instead of http://google.com.
The key difference is that this is an real integration test. You're not mocking at the JS level, instead you're sending real HTTP requests, testing what will really be sent and received, and exactly how your full Node + application code will respond to that in practice.
You can mock entirely at the JS level, and your tests will be marginally quicker (in the region of 2ms vs 10ms per test), but it's very easy to get inaccurate results, and have passing tests but broken real-world functionality.