title: Jest not handling errors from expect() in subscribe() of RxJS observable
body: <p>I've been trying to get Jest working with RxJS and am having trouble with Jest not propagating errors from inside the subscribe callback.</p>
  
  <p>Here is a sample test I've tried that is not working:</p>
  
  <pre class="lang-js prettyprint-override"><code>import {of} from 'rxjs';
  
  test('should fail', () =&gt; {
    of(false).subscribe(val =&gt; {
      expect(val).toBe(true);
    });
  });
  </code></pre>
  
  <p>The above test should fail, but it passes. I've googled around and found the following solution:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/50930249/failing-expect-inside-subscribe-does-not-mark-test-as-invalid">Failing expect() inside subscribe() does not mark test as invalid</a></li>
  </ul>
  
  <p>This suggests using the "done" syntax in jest to solve the issue. While using the "done" callback does get the above test to fail, there are a number of issues with this approach:</p>
  
  <h3>Undescriptive errors</h3>
  
  <p>The test fails because the 'expect' call in subcribe() throws an error, resulting in 'done()' never getting called. The test then times out, waiting for done. So instead of propagating the 'expect' error, it is causing a timeout error, which means every test that fails in the expect clause will show a timeout error instead of the actual error message of the failed 'expect' call.</p>
  
  <h3>Tests take longer to fail</h3>
  
  <p>Because all tests are failing due to a timeout error, that means it takes 5 seconds for each test to fail (async tests timeout after 5 seconds). This can dramatically increase the amount of time for tests to run</p>
  
  <h3>Poor use of done</h3>
  
  <p>The <code>done</code> callback is meant to support asynchronous use cases for testing. But rxjs is not necessarily asynchronous. The code I inlined above actually runs synchronously. For example, the following test will pass:</p>
  
  <pre class="lang-js prettyprint-override"><code>import {of} from 'rxjs';
  
  test('should pass', () =&gt; {
    let didRunSynchronously = false;
    of(true).subscribe(() =&gt; {
      didRunSynchronously = true;
    });
    expect(didRunSynchronously).toBe(true);
  });
  </code></pre>
  
  <p>It seems strange to have to use asynchronous semantics to solve a problem for a synchronous test.</p>
  
  <p>Wondering if anyone has come up with a good solution for testing in rxjs that will result in the <code>expect</code> calls to properly get handled by the testing library.</p>
  
  <p>Thanks in advance!</p>
  
  <h3>Relevant dependencies in package.json:</h3>
  
  <pre class="lang-js prettyprint-override"><code> "dependencies": {
      "@babel/polyfill": "^7.0.0",
      "classnames": "^2.2.6",
      "history": "^4.7.2",
      "json-stringify-pretty-compact": "^1.2.0",
      "minimist": "^1.2.0",
      "normalize.css": "^8.0.0",
      "nullthrows": "^1.1.0",
      "react": "^16.5.2",
      "react-dom": "^16.5.2",
      "react-router-dom": "^4.3.1",
      "rxjs": "^6.3.3",
    },
    "devDependencies": {
      "@babel/core": "^7.2.2",
      "@babel/plugin-proposal-class-properties": "^7.1.0",
      "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
      "@babel/preset-env": "^7.1.0",
      "@babel/preset-flow": "^7.0.0",
      "@babel/preset-react": "^7.0.0",
      "babel-core": "^7.0.0-bridge.0",
      "babel-env": "^2.4.1",
      "babel-eslint": "^10.0.1",
      "babel-jest": "^23.6.0",
      "babel-loader": "^8.0.4",
      "copy-webpack-plugin": "^4.5.3",
      "css-loader": "^1.0.0",
      "eslint": "^5.9.0",
      "eslint-plugin-flowtype": "^3.2.0",
      "eslint-plugin-import": "^2.14.0",
      "eslint-plugin-react": "^7.11.1",
      "eslint-watch": "^4.0.2",
      "flow-bin": "^0.83.0",
      "html-webpack-plugin": "^3.2.0",
      "jest": "^23.6.0",
      "prettier": "^1.15.3",
      "style-loader": "^0.23.1",
      "webpack": "^4.20.2",
      "webpack-cli": "^3.1.2",
      "webpack-dev-server": "^3.1.9"
    }
  </code></pre>
  
  <h3>.babelrc file</h3>
  
  <pre class="lang-js prettyprint-override"><code>{
    "plugins": [
      "module:@babel/plugin-proposal-class-properties",
      "module:@babel/plugin-proposal-object-rest-spread"
    ],
    "presets": [
      ["module:@babel/preset-env", { "targets": { "node": "6.10" } }],
      "module:@babel/preset-flow"
    ]
  }
  </code></pre>