title: How to solve Cannot set property '_eventListeners' of undefined error with jest/jsdom?
body: <p>I am replacing karma with jest and when I created all needed files and settings which you can see below. When I executed npm jest got an error:</p>
  
  <pre><code>Test suite failed to run
  TypeError: Cannot set property '_eventListeners' of undefined
  at Window.close (node_modules/jsdom/lib/jsdom/browser/Window.js:475:51)
  </code></pre>
  
  <p>I found a solution with editing node_modules/* files that don't make sense.
  When I tried to switch testEnvironment to 'node' it's looked ok but I think that's not a good solution when it isn't node service project.</p>
  
  <p>/jest.config.js     </p>
  
  <pre><code>module.exports = {
      coverageReporters: [
          "html",
          "text",
          "cobertura"
      ],
      globals: {
          "ts-jest": {
              tsConfig: "tsconfig.test.json",
              babelConfig: true
          }
      },
      moduleFileExtensions: [
          "ts",
          "tsx",
          "js",
          "jsx",
          "json",
          "node",
          "d.ts",
          "scss"
      ],
      moduleNameMapper: {
          "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "&lt;rootDir&gt;/test/mocks/fileMock.js",
          "\\.(css|sass|scss)$": "&lt;rootDir&gt;/test/mocks/styleMock.js",
          "^worker-loader!": "&lt;rootDir&gt;/test/mocks/workerLoaderMock.js",
          "^resize-observer-polyfill$": "&lt;rootDir&gt;/test/mocks/resizeObserverPolyfillMock.js",
          "applicationinsights-js": "&lt;rootDir&gt;/test/mocks/appInsightsMock.js"
      },
      reporters: [
          "default",
          "jest-junit"
      ],
      setupFiles: [
          "&lt;rootDir&gt;/test/mocks/setupJest.js"
      ],
      setupFilesAfterEnv: [
          "&lt;rootDir&gt;/test/mocks/matchMedia.js"
      ],
      transform: {
          "^.+\\.(js|jsx|ts|tsx|d.ts)$": "ts-jest"
      },
      testMatch: [
          "&lt;rootDir&gt;/test/**/*-test.tsx"
      ],
      timers: "fake"
  };
  </code></pre>
  
  <p>/setupJest.js</p>
  
  <pre><code>global.Intl = require("intl");
  global.fetch = require('jest-fetch-mock')
  global.AppSettings = {
      AUTHORITY_URL: "https://auth.blah.com",
      INSTRUMENTATION_KEY: "APP_SETTINGS_KEY",
      REALTIME_URL_BASE: "https//:realtime.blah.com"
  };
  
  </code></pre>
  
  <p>my-test.js</p>
  
  <pre><code>import { Tooltip } from "../../src/components/shared";
  import { expect, React, shallow } from "../test-utils";
  
  describe("Tooltip with empty properties", () =&gt; {
      const component = shallow(&lt;Tooltip tooltipText="" /&gt;);
  
      it("should have no text", () =&gt; {
          expect(component.find("span.tooltip-text").text()).to.have.length(0);
      });
  
      it("should have 'tooltip-container' class", () =&gt; {
          expect(component.hasClass("tooltip-container")).to.be.true;
      });
  
      it("should have child with 'tooltip-text' class", () =&gt; {
          expect(component.childAt(0).hasClass("tooltip-text")).to.be.true;
      });
  });
  
  describe("Tooltip with set properties", () =&gt; {
      const expectedClass = "test-class";
      const expectedText = "Test tooltip text";
      const component = shallow(&lt;Tooltip tooltipText={expectedText} className={expectedClass} /&gt;);
  
      it("should have the expected text", () =&gt; {
          expect(component.find("span.tooltip-text").text()).to.be.equal(expectedText);
      });
  
      it("should have the expected classes", () =&gt; {
          expect(component.hasClass("tooltip-container")).to.be.true;
          expect(component.hasClass(expectedClass)).to.be.true;
      });
  });
  </code></pre>