Repository: facebook/jest
File: packages/jest-mock/src/__tests__/index.test.ts (TypeScript)

Code before:
        get methodTwo() {
          return methodTwoReturn;
        },
      };
      const obj = Object.create(prototype, {});

      moduleMocker.spyOn(obj, 'methodOne', 'get').mockReturnValue(100);
      moduleMocker.spyOn(obj, 'methodTwo', 'get').mockReturnValue(200);

      // Return values are mocked.
      expect(methodOneReturn).toBe(10);
      expect(methodTwoReturn).toBe(20);
      expect(obj.methodOne).toBe(100);
      expect(obj.methodTwo).toBe(200);

      moduleMocker.resetAllMocks();

      // After resetting all mocks, the methods return the original return value.
      expect(methodOneReturn).toBe(10);
      expect(methodTwoReturn).toBe(20);
      expect(obj.methodOne).toBe(10);
      expect(obj.methodTwo).toBe(20);
    });

    it('supports restoring a spy on the prototype chain', () => {
      let methodOneCalls = 0;
      const prototype = {
        get methodOne() {
          return function () {
            methodOneCalls++;
          };
        },
      };
      const obj = Object.create(prototype, {});

      const spy1 = moduleMocker.spyOn(obj, 'methodOne', 'get');

      obj.methodOne();

      // The spy and the original function are called.
      expect(methodOneCalls).toBe(1);
      expect(spy1.mock.calls).toHaveLength(1);

      spy1.mockRestore();

      obj.methodOne();

      // After restoring the spy only the real method bumps its call count, not the spy.
      expect(methodOneCalls).toBe(2);
      expect(spy1.mock.calls).toHaveLength(0);
    });

Review comment (suggestion):
A function can have properties. Removed this case and moved `null` and `undefined` here from the above test.

Code after:
      expect(methodOneReturn).toBe(0);
      expect(obj.methodOne).toBe(10);

      spy1.mockReset();

      // After resetting the spy, the method returns the original return value.
      expect(methodOneReturn).toBe(0);
      expect(obj.methodOne).toBe(0);
    });

    it('supports resetting all spies on the prototype chain', () => {
      const methodOneReturn = 10;
      const methodTwoReturn = 20;
      const prototype = {
        get methodOne() {
          return methodOneReturn;
        },
        get methodTwo() {
          return methodTwoReturn;
        },
      };
      const obj = Object.create(prototype, {});

      moduleMocker.spyOn(obj, 'methodOne', 'get').mockReturnValue(100);
      moduleMocker.spyOn(obj, 'methodTwo', 'get').mockReturnValue(200);

      // Return values are mocked.
      expect(methodOneReturn).toBe(10);
      expect(methodTwoReturn).toBe(20);
      expect(obj.methodOne).toBe(100);
      expect(obj.methodTwo).toBe(200);

      moduleMocker.resetAllMocks();

      // After resetting all mocks, the methods return the original return value.
      expect(methodOneReturn).toBe(10);
      expect(methodTwoReturn).toBe(20);
      expect(obj.methodOne).toBe(10);
      expect(obj.methodTwo).toBe(20);
    });

    it('supports restoring a spy on the prototype chain', () => {
      let methodOneCalls = 0;
      const prototype = {
        get methodOne() {
          return function () {
            methodOneCalls++;
          };
        },
      };
      const obj = Object.create(prototype, {});