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

No fallback response defined for GET to https://API_URL/api/v1/invite/undefined #299

Closed
sahibjotsaggu opened this issue Apr 13, 2018 · 5 comments

Comments

@sahibjotsaggu
Copy link

I am trying to mock an API call to /invite/[INVITE_TOKEN] but I keep getting No fallback response defined for GET to https://API_URL/api/v1/invite/undefined.

import React from 'react';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import * as actions from 'actions/cardActions';
import * as types from 'actions/cardActions/constants';
import configureMockStore from 'redux-mock-store';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('container', () => {
 afterEach(() => {
   fetchMock.reset();
   fetchMock.restore();
 });

 it('creates [ACTION_TYPE] action when fetching [THINGS] has been done', () => {
   fetchMock.getOnce('/invite/[INVITE_TOKEN_HERE]', {
     "token": "INVITE_TOKEN_HERE",
     "space_id": [INTEGER]
   });
 });
});
@wheresrhys
Copy link
Owner

The error is telling you that https://API_URL/api/v1/invite/undefined has not been mocked. So 3 things jump out at me:

  • you're not passing API_URL into the mock
  • you're missing /api/v1 from the mock
  • INVITE_TOKEN is undefined in the url, which suggests you're not defining it properly in the test

Closing for now. Please reopen and create a demo repo recreating the problem if it persists

@jharris4
Copy link

jharris4 commented Apr 1, 2019

Just FYI I hit this same error, and it seems that it is caused by either not having body or response set in the options. it had nothing to do with the matcher/url.

@ChetnaGupta
Copy link

@jharris4 Can you share the exact code snippet where we need to add body/response in options for reference?

@jharris4
Copy link

jharris4 commented Jun 9, 2019

@ChetnaGupta sorry, it has been a while since I looked at this, but I can tell you the changes I made to update to the new version:

In most of our tests it was as simple as removing this line:

sendAsJson: true

And for one of the tests, I had to replace:

response: {
  status: status,
  headers: {
    ['Content-Type']: 'application/json'
  },
  body: '',
  sendAsJson: true
}

with just:

response: status

@ChetnaGupta
Copy link

Thanks @jharris4

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

4 participants