-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration testing of Relay containers with Jest against a working GraphQL backend not working #1281
Comments
Hello guys! |
At a quick glance nothing stands out as being obviously incorrect about the test setup; I'd expect it to fetch data. We'll need more information to help debug. Is render called? Is your network layer called (does it even make the HTTP request?). I would try putting breakpoints/log statements in RelayRenderer to make sure that it's even executing. It sounds like something is going weird and a component is mocked by Jest even though you don't expect it to be. |
I found out that there was an exception during the fetching (sorry, I'm kind of new to the node debugging I had to do this first..):
It's this line in the RelayQueryRequest in the source code. |
Hmm. @cpojer any ideas? |
The "moduleNameMapper" config object can be used to map from one module to another, if that is the case. |
After adding the Here's the output when I run Jest without test path reg ex:
As you see the And here's the output when I specify the test path reg ex to execute only the
See? Why? What changes inside Jest that causes the exception? It is this line in transpiled code (I've added the RelayQueryRequest.prototype.getQueryString = function getQueryString() {
var printedQuery = this._printedQuery;
if (!printedQuery) {
console.log('\nin printedQuery');
printedQuery = require('./printRelayQuery')(this._query); // <-- this one throws **the** exception
console.log('printedQuery', printedQuery);
this._printedQuery = printedQuery;
}
return printedQuery.text;
}; To make things worse I can tell you that the same behaviour as in the second case I see when PS I also removed const babel = require('babel-core');
const jestPreset = require('babel-preset-jest');
const fbjsPreset = require('babel-preset-fbjs/configure')({
stripDEV: false,
});
module.exports = {
process(src, filename) {
if (babel.util.canCompile(filename)) {
return babel.transform(src, {
filename,
presets: [
jestPreset,
fbjsPreset,
],
retainLines: true,
}).code;
}
return src;
},
}; Any ideas? |
That's really strange. The fact that it works on one of the tests seems important. Is there anything different about the two tests that could be causing Jest to behave differently? I'm going to close this since it doesn't appear to be a Relay issue per-se, but feel free to continue discussion here. You may also want to file an issue on http://github.com/facebook/jest so that more Jests experts can see it and help out. |
I don't change any test between these two runs. I even specify the The first test jest.disableAutomock();
import React from 'react';
import ReactDom from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import SignIn from '../src/components/SignIn';
xdescribe('SignIn', () => {
it('shows the social login buttons', () => {
const signin = TestUtils.renderIntoDocument(
<div><SignIn /></div>
);
expect(signin).not.toBe(null);
const signinNode = ReactDom.findDOMNode(signin);
expect(signinNode).not.toBe(null);
expect(signinNode.textContent).toMatch(/Sign In with Facebook/);
});
}); Here PS I'll file an issue to the Jest repo. |
@josephsavona I finally got some results but there're not solving the issue tho. I'm just asking for an advice. Long story short is that I could not debug my test because jest has some kind of issue when the OSS Relay is built with And here's what I've got at the moment. Relay makes the query!! I can see it in my backend server log. But. The Can you give my some further direction on how can I debug this? Thanks! |
@GrigoryPtashko have u some progress on this? could u share a repo or a gist with ur current solution? |
@sibelius @lucasbento sorry for keeping silence. My macbook was in the service. I'm glad I'm not alone in this question.. I guess you've already guessed that I have a working solution for Jest 14 but not for Jest >= 15. Here's the issue with the repro and the example for Jest 14 jestjs/jest#1898. Guys from the Jest team do not answer it unfortunately. |
@GrigoryPtashko u should write a blog post about it |
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
package.json
for the Jest:Here's the
.babelrc
I'm using:Here's the test itself. It must make a request to `http://localhost:10000/q' GraphQL endpoint to fetch a simple piece that represents the info about the current user ('me').
The problem is that the test passes. But in my opinion it must fail at this line inside the
render()
expect(this.props.root.me.authorities[0].authority).toEqual('ROLE_ANONYMOUS_AAA');
. It seems like therender()
method is not executed at all.I'm running Jest like this
Does this all suppose to work at all?
Thank you.
The text was updated successfully, but these errors were encountered: