Skip to content
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

Timeout error: No match for request #27

Closed
Robinnnnn opened this issue Feb 25, 2016 · 1 comment
Closed

Timeout error: No match for request #27

Robinnnnn opened this issue Feb 25, 2016 · 1 comment

Comments

@Robinnnnn
Copy link

I'm a novice so this may be a trivial question.

I'm currently trying to test my actions for signing up a user. For some reason my post request fails by timing out, when my endpoints seem to be fine.

// the test
it('creates SIGNUP_USER_SUCCESS when user completes signup', (done) => {

    var signupUser = require('../actions/auth/signup').signupUser;

    nock('http://api.dockerhost')
        .post('/signup', {
            first_name: 'Robin',
            last_name: 'Kim',
            username: 'rokim8@gmail.com',
            password: 'password'
        })
        .reply(200, {
            body: {
                user: {
                    username: 'rokim8@gmail.com'
                }
            }
        })

    const expectedActions = [
        { type: constants.SIGNUP_USER_REQUEST },
        { type: constants.SIGNUP_USER_SUCCESS }
    ];

    const store = mockStore({ user: {}}, expectedActions, done);
    store.dispatch(signupUser('Robin Kim', 'rokim8@gmail.com', 'password'));
})

// the action
const signupUser = (name, username, password) => {

    const first_name = name.split(' ').slice(0, -1).join(' ');
    const last_name = name.split(' ').slice(-1).join(' ');
    const url = `http://api.dockerhost/signup`;
    const data = { first_name, last_name, username, password }

    return (dispatch) => {
        dispatch(signupUserRequest());
        return request
          .post(url)
          .type('form')
          .send(data)
          .end()
          .then((response) => {
            console.log('the response', response)
            dispatch(signupUserSuccess());
            return dispatch(loginUser(username, password, '/downloads'));
          })
          .catch((error) => {
            console.log('error', error) // this is where I get the error
            return dispatch(signupUserFailure({
                response: {
                    statusText: error.response.body.errors.username.message,
                    field: error.response.body.errors.username.path
                }
            }))
          })
    }
}

// the error response
`{ [Error: Nock: No match for request POST http://api.dockerhost/signup first_name=Robin&last_name=Kim&username=rokim8%40gmail.com&password=password] status: 404, statusCode: 404, response: undefined }`

// the test log
`Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.`

It seems like it simply cannot hit my /signup endpoint, but I'm unsure as to why.

@arnaudbenard
Copy link
Contributor

The problem is with nock. Based on my experience, I would advise you to use the DEBUG=nock.* env variables to see what is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants