jestjs - Integration testing of Relay containers with Jest against a working GraphQL backend not working -
i'd implement integration testing of relay containers against running graphql backend server. i'm going use jest this. i'd unit testing of react components works expected jest setup. here's have in package.json
jest:
"jest": { "modulefileextensions": [ "js", "jsx" ], "moduledirectories": [ "node_modules", "src" ], "modulenamemapper": { "^.+\\.(css|less)$": "<rootdir>/src/stylemock.js", "^.+\\.(gif|ttf|eot|svg|png)$": "<rootdir>/src/filemock.js" }, "unmockedmodulepathpatterns": [ "<rootdir>/node_modules/react/", "<rootdir>/node_modules/react-dom/", "<rootdir>/node_modules/react-addons-test-utils/", "<rootdir>/node_modules/react-relay/" ] }
here's .babelrc
i'm using:
{ "presets": ["es2015", "react", "stage-0"], "plugins": ["./babelrelayplugin.js"] }
here's test itself. must make request `http://localhost:10000/q' graphql endpoint fetch simple piece represents info current user ('me').
jest.disableautomock(); import react 'react'; import relay 'react-relay'; import testutils 'react-addons-test-utils'; import relaynetworkdebug 'react-relay/lib/relaynetworkdebug'; relaynetworkdebug.init(); relay.injectnetworklayer( new relay.defaultnetworklayer('http://localhost:10000/q') ); describe('me', () => { it('can make request /q anyway', () => { class rootroute extends relay.route { static queries = { root: (component) => 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 ( <div> {this.props.root.me.firstname} </div> ); } } const appcontainer = relay.createcontainer(approot, { fragments: { root: () => relay.ql` fragment on root { me { firstname email authorities { authority } } } `, }, }); const container = testutils.renderintodocument( <div> <relay.rootcontainer component={appcontainer} route={new rootroute()} /> </div> ); expect(container).not.tobe(null); }); });
the problem test passes. in opinion must fail @ line inside render()
expect(this.props.root.me.authorities[0].authority).toequal('role_anonymous_aaa');
. seems render()
method not executed @ all.
i'm running jest this
./node_modules/.bin/jest
does suppose work @ all?
thank you.
this possible, take on code: https://github.com/sibelius/relay-integration-test
and on blog post: https://medium.com/entria/relay-integration-test-with-jest-71236fb36d44#.ghhvvbbvl
the missing piece need polyfill xmlhttprequest make work react native.
and need polyfill fetch react web
Comments
Post a Comment