Repository: jestjs/jest (TypeScript)

Issue:
[Bug]: TypeError: Cannot read properties of undefined (reading 'bind')
### Version

27.4.5

### Steps to reproduce

1. clone repo https://github.com/rainbow-industries/jest-bug
2. npm i
3. npm test
4. experience the bug
```bash
npm test

> jest-bug@1.0.0 test
> jest --config=jest.config.js

 FAIL  ./demo.test.js
  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'bind')

      at Runtime._createJestObjectFor (node_modules/jest-runtime/build/index.js:2193:46)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.372 s
Ran all test suites
```

### Expected behavior

I expect the test not to fail since it just contains one console.log statement.

### Actual behavior

The test fails with an error that looks very similar to this regression:
https://github.com/facebook/jest/issues/12189#issuecomment-1001059449 

### Additional context

I'd like to run test without transformations with ES Modules. That's the reason i use `jest-environment-jsdom-sixteen` as `testEnvironment` in the config.

### Environment

```shell
System:
  OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
  CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
Binaries:
  Node: 16.13.1 - /usr/bin/node
  npm: 8.1.2 - /usr/bin/npm
npmPackages:
  jest: ^27.4.5 => 27.4.5
```



Hints:
I have this exact error with jest 27.4.5. Add `"jest-environment-jsdom": "^27.4.4"` fix it. Reversing jest to 26 also fix it.

Patch:
diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts
--- a/packages/jest-runtime/src/index.ts
+++ b/packages/jest-runtime/src/index.ts
@@ -1924,7 +1924,13 @@ export default class Runtime {
     };
     const fn = this._moduleMocker.fn.bind(this._moduleMocker);
     const spyOn = this._moduleMocker.spyOn.bind(this._moduleMocker);
-    const mocked = this._moduleMocker.mocked.bind(this._moduleMocker);
+    const mocked =
+      this._moduleMocker.mocked?.bind(this._moduleMocker) ??
+      (() => {
+        throw new Error(
+          'Your test environment does not support `mocked`, please update it.',
+        );
+      });
 
     const setTimeout = (timeout: number) => {
       if (this._environment.global.jasmine) {


Test patch:
diff --git a/e2e/__tests__/testEnvironment.test.ts b/e2e/__tests__/testEnvironment.test.ts
--- a/e2e/__tests__/testEnvironment.test.ts
+++ b/e2e/__tests__/testEnvironment.test.ts
@@ -5,9 +5,18 @@
  * LICENSE file in the root directory of this source tree.
  */
 
-import {json as runWithJson} from '../runJest';
+import {tmpdir} from 'os';
+import * as path from 'path';
+import slash = require('slash');
+import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
+import runJest, {json as runWithJson} from '../runJest';
 import * as testFixturePackage from '../test-environment/package.json';
 
+const DIR = path.resolve(tmpdir(), 'test-env-no-mocked');
+
+beforeEach(() => cleanup(DIR));
+afterAll(() => cleanup(DIR));
+
 it('respects testEnvironment docblock', () => {
   expect(testFixturePackage.jest.testEnvironment).toEqual('node');
 
@@ -16,3 +25,40 @@ it('respects testEnvironment docblock', () => {
   expect(result.success).toBe(true);
   expect(result.numTotalTests).toBe(3);
 });
+
+it('handles missing `mocked` property', () => {
+  createEmptyPackage(DIR);
+  writeFiles(DIR, {
+    'env.js': `
+      const Node = require('${slash(
+        require.resolve('jest-environment-node'),
+      )}');
+
+      module.exports = class Thing extends Node {
+        constructor(...args) {
+          super(...args);
+
+          this.moduleMocker.mocked = undefined;
+        }
+      };
+    `,
+    'test.js': `
+      /**
+       * @jest-environment ./env.js
+       */
+
+      jest.mocked();
+
+      test('halla', () => {
+        expect(global.thing).toBe('nope');
+      });
+    `,
+  });
+
+  const {exitCode, stderr} = runJest(DIR);
+
+  expect(exitCode).toBe(1);
+  expect(stderr).toContain(
+    'Your test environment does not support `mocked`, please update it.',
+  );
+});