title: TypeError during Jest's spyOn: Cannot set property getRequest of #<Object> which has only a getter
body: <p>I'm writing a React application with TypeScript. I do my unit tests using Jest.</p>
  
  <p>I have a function that makes an API call:</p>
  
  <pre><code>import { ROUTE_INT_QUESTIONS } from "../../../config/constants/routes";
  import { intQuestionSchema } from "../../../config/schemas/intQuestions";
  import { getRequest } from "../../utils/serverRequests";
  
  const intQuestionListSchema = [intQuestionSchema];
  
  export const getIntQuestionList = () =&gt; getRequest(ROUTE_INT_QUESTIONS, intQuestionListSchema);
  </code></pre>
  
  <p>The <code>getRequest</code> function looks like this:</p>
  
  <pre><code>import { Schema } from "normalizr";
  import { camelizeAndNormalize } from "../../core";
  
  export const getRequest = (fullUrlRoute: string, schema: Schema) =&gt;
    fetch(fullUrlRoute).then(response =&gt;
      response.json().then(json =&gt; {
        if (!response.ok) {
          return Promise.reject(json);
        }
        return Promise.resolve(camelizeAndNormalize(json, schema));
      })
    );
  </code></pre>
  
  <p>I wanted to try the API function using Jest like this:</p>
  
  <pre><code>import fetch from "jest-fetch-mock";
  import { ROUTE_INT_QUESTIONS } from "../../../config/constants/routes";
  import {
    normalizedIntQuestionListResponse as expected,
    rawIntQuestionListResponse as response
  } from "../../../config/fixtures";
  import { intQuestionSchema } from "../../../config/schemas/intQuestions";
  import * as serverRequests from "./../../utils/serverRequests";
  import { getIntQuestionList } from "./intQuestions";
  
  const intQuestionListSchema = [intQuestionSchema];
  
  describe("getIntQuestionList", () =&gt; {
    beforeEach(() =&gt; {
      fetch.resetMocks();
    });
  
    it("should get the int question list", () =&gt; {
      const getRequestMock = jest.spyOn(serverRequests, "getRequest");
      fetch.mockResponseOnce(JSON.stringify(response));
  
      expect.assertions(2);
      return getIntQuestionList().then(res =&gt; {
        expect(res).toEqual(expected);
        expect(getRequestMock).toHaveBeenCalledWith(ROUTE_INT_QUESTIONS, intQuestionListSchema);
      });
    });
  });
  </code></pre>
  
  <p>The problem is that the line with <code>spyOn</code> throws the following error:</p>
  
  <pre><code>  ● getRestaurantList › should get the restaurant list
  
      TypeError: Cannot set property getRequest of #&lt;Object&gt; which has only a getter
  
        17 |
        18 |   it("should get the restaurant list", () =&gt; {
      &gt; 19 |     const getRequestMock = jest.spyOn(serverRequests, "getRequest");
           |                                 ^
        20 |     fetch.mockResponseOnce(JSON.stringify(response));
        21 |
        22 |     expect.assertions(2);
  
        at ModuleMockerClass.spyOn (node_modules/jest-mock/build/index.js:706:26)
        at Object.spyOn (src/services/api/IntQuestions/intQuestions.test.ts:19:33)
  </code></pre>
  
  <p>I googled this and only found posts about hot reloading. So what could cause this during Jest test? How can I get this test to pass?</p>