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

Testing RSAA api calls #242

Closed
ghost opened this issue Feb 10, 2020 · 3 comments
Closed

Testing RSAA api calls #242

ghost opened this issue Feb 10, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 10, 2020

@nason
So, I am trying to write test cases for api calls. I tried following the readme but the test-case is always getting failed.
On giving relative url link, I am getting this, instead of SUCCESS:

      "error": true,
      "meta": undefined,
      "payload": [ApiError: 404 - Not Found],
      "type": "@@user/USER_FAILURE"

I also tried giving the full endpoint, and got this:

        "error": true,
        "meta": undefined,
        "payload": [RequestError: Network request failed],
        "type": "@@user/USER_FAILURE"

Is this a redux-thunk problem or is it something else? Isn't there any other way to mock redux-api-middleware actions?

UPDATE
This is not a redux-thunk problem. I implemented a sample test case using redux-thunk and native fetch method and it worked perfectly in tests.
Apparently, redux-api-middleware isn't able to do the network-request and I don't know why, in spite of using fetch internally.

@ghost
Copy link
Author

ghost commented Feb 11, 2020

SOLVED

So I passed the fetch: fetch in my action creators i.e.

[RSAA]: {
    endpoint: "/something",
    ...
    fetch: fetch
}

and it worked.
I don't know why the problem, which should have never occurred in the first place, occurred, but it seems to work for the test-cases.

@ghost ghost closed this as completed Feb 11, 2020
@iamandrewluca
Copy link
Collaborator

iamandrewluca commented Feb 11, 2020

@sudh-0 you can also pass a global fetch for all actions
Instead of apiMiddleware you can use createMiddleware({ fetch })

https://github.com/agraboso/redux-api-middleware#createmiddlewareoptions

@guzzijones
Copy link

good gosh thanks for reporting this. I just had the exact same issue.

This issue was closed.
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