Integration testing of Relay containers with Jest against a working GraphQL backend not working
<p>I'd like to implement the integration testing of my Relay containers against a running GraphQL backend server. I'm going to use Jest for this. I'd like to say that unit testing of React components works well as expected with my Jest setup.
Here's what I have in the <code>package.json</code> for the Jest:</p>

<pre><code>"jest": {
    "moduleFileExtensions": [
      "js",
      "jsx"
    ],
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "moduleNameMapper": {
      "^.+\\.(css|less)$": "&lt;rootDir&gt;/src/styleMock.js",
      "^.+\\.(gif|ttf|eot|svg|png)$": "&lt;rootDir&gt;/src/fileMock.js"
    },
    "unmockedModulePathPatterns": [
      "&lt;rootDir&gt;/node_modules/react/",
      "&lt;rootDir&gt;/node_modules/react-dom/",
      "&lt;rootDir&gt;/node_modules/react-addons-test-utils/",
      "&lt;rootDir&gt;/node_modules/react-relay/"
    ]
}
</code></pre>

<p>Here's the <code>.babelrc</code> I'm using:</p>

<pre><code>{
  "presets": ["es2015", "react", "stage-0"],
  "plugins": ["./babelRelayPlugin.js"]
}
</code></pre>

<p>Here's the test itself. It must make a request to `<a href="http://localhost:10000/q" rel="nofollow">http://localhost:10000/q</a>' GraphQL endpoint to fetch a simple piece that represents the info about the current user ('me').</p>

<pre><code>jest.disableAutomock();

import React from 'react';
import Relay from 'react-relay';
import TestUtils from 'react-addons-test-utils';
import RelayNetworkDebug from 'react-relay/lib/RelayNetworkDebug';

RelayNetworkDebug.init();
Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('http://localhost:10000/q')
);

describe('Me', () =&gt; {
  it('can make request to /q anyway', () =&gt; {
    class RootRoute extends Relay.Route {
      static queries = {
        root: (Component) =&gt; Relay.QL`
            query {
                root {
                    ${Component.getFragment('root')}
                }
            }
        `,
      };

      static routeName = 'RootRoute';
    }

    class AppRoot extends React.Component {
      static propTypes = {
        root: React.PropTypes.object,
      };

      render() {
        expect(this.props.root).not.toBe(null);
        expect(this.props.root.me).not.toBe(null);
        expect(this.props.root.me.firstName).not.toBe(null);
        expect(this.props.root.me.authorities[0]).not.toBe(null);
        expect(this.props.root.me.authorities[0].authority).toEqual('ROLE_ANONYMOUS_AAA');

        return (
          &lt;div&gt;
            {this.props.root.me.firstName}
          &lt;/div&gt;
        );
      }
    }

    const AppContainer = Relay.createContainer(AppRoot, {
      fragments: {
        root: () =&gt; Relay.QL`
            fragment on Root {
                me {
                    firstName
                    email
                    authorities {
                        authority
                    }
                }
            }
        `,
      },
    });

    const container = TestUtils.renderIntoDocument(
      &lt;div&gt;
        &lt;Relay.RootContainer Component={AppContainer} route={new RootRoute()} /&gt;
      &lt;/div&gt;
    );

    expect(container).not.toBe(null);
  });
});
</code></pre>

<p>The problem is that the test passes. But in my opinion it <strong>must fail</strong> at this line inside the <code>render()</code> <code>expect(this.props.root.me.authorities[0].authority).toEqual('ROLE_ANONYMOUS_AAA');</code>. It seems like the <code>render()</code> method is not executed at all.</p>

<p>I'm running Jest like this</p>

<pre><code>./node_modules/.bin/jest
</code></pre>

<p>Does this all suppose to work at all?</p>

<p>Thank you.</p>