test --watch always exits when a promise is unhandled
Created by: jackielii
Is this a bug report?
No.
In case of a complicated flow control, the yarn test
simply exists with:
.../node_modules/react-scripts/scripts/test.js:22
throw err;
^
[object Object]
This is not very helpful.
E.g. my test:
it('should connect dispatch not authenticated', done => {
mockFetch(null, 401); // mocks global.fetch
const Component = props => {
const { callGraphQL } = props;
const params = { query: '{hello}' };
const result = callGraphQL(params)
.then(response => {
expect(`shouldn't execute catch block`).toBe('not executed');
})
.catch(error => {
expect(error.errors).toHaveLength(1);
});
Promise.all([result, resultIgnoreError]).then(done);
return null;
const dispatch = jest.fn();
const ConnectedComponent = connectGraphQL()(Component);
const wrapper = mount(<ConnectedComponent />, createOption(dispatch));
expect(wrapper.find(Component)).toHaveLength(1);
};
In the test above, I thought I caught all the promise rejection, but it still failed and the error yarn test
gave me is not very useful.
Now the error is within the catch block. It throw because access error.errors. My fault. But react-script shouldn't exit without useful information.
It should print a helpful message, fail the test instead of exit with code 1 and print [object Object]
Can you also reproduce the problem with npm 4.x?
(Write your answer here.)YES
Which terms did you search for in User Guide?
unhandledPromise
(Write your answer here if relevant.)
Environment
-
node -v
: v7.7.1 -
npm -v
:4.1.2 -
yarn --version
(if you use Yarn):0.27.5 -
npm ls react-scripts
(if you haven’t ejected): react-scripts@1.0.7
Then, specify:
- Operating system:Xubuntu 1604
- Browser and version (if relevant):