title: Angular 6 Unit Tests: An error was thrown in afterAll\nReferenceError: Can't find variable: $ thrown
body: <p>When running my unit tests, from time to time, even if they pass, at the end of all the tests running, I will get the following error.</p>
  
  <p>On my Jenkins CI build running PhantomJS:</p>
  
  <pre><code>.PhantomJS 2.1.1 (Linux 0.0.0) ERROR
    {
      "message": "An error was thrown in afterAll\nReferenceError: Can't find variable: $ thrown",
      "str": "An error was thrown in afterAll\nReferenceError: Can't find variable: $ thrown"
    }
  </code></pre>
  
  <p>Or on Chrome:</p>
  
  <pre><code>Chrome 67.0.3396 (Windows 7 0.0.0) ERROR
    {
      "message": "An error was thrown in afterAll\n[object ErrorEvent] thrown",
      "str": "An error was thrown in afterAll\n[object ErrorEvent] thrown"
    }
  </code></pre>
  
  <p>I also have really unreliable tests, without changing anything some times they would succeed and other times the same tests would fail, so I knew something weird was going on. </p>