You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background:
I've created a React project with a Clean Architecture approach and now I want to unit-test the Use-Cases (which call Repositories, which call Data-Sources, so on and so on) against mocked API-data to make sure that the call-and-response-flow works throughout all layers (leaving the UI aside - will be covered in UI- & E2E-Tests).
Problem/Question:
When unit-testing a Use-Cases, there are multiple API-calls involved (for example the first one to refresh an access token and the second one to actually get the desired content). Therefore, I need a way define which responses should be returned for which requests.
So, this is my test case to get available offers from the marketplace:
Test-Result:
The result of this is the following error being thrown in the OfferRepository:
Get available offers › successfully receives available offers
FetchError: invalid json response body at reason: Unexpected end of JSON input
at node_modules/node-fetch/lib/index.js:273:32
What should happen:
By calling the GetAvailableOffers-Use-Case, the BlueprintOffersAPIClient requests a new valid access token. For this, the first Promise should be received. After that, all available offers should be fetched and the second Promise should be received.
Specific question:
How can I specify mocked responses for URLs/individual requests, so that when running my test-case my token-refresh-request receives the /connect/authorize mocked response, but my get-available-offers-request receives the mocked response for /api/Offers?
The text was updated successfully, but these errors were encountered:
I have this exact problem. Very surprised that this use case hasn't come up. Seems like the API encourages you to do this with chaining mockIf and doMockIf but they dont work. I.e. the follow test fails:
Background:
I've created a React project with a Clean Architecture approach and now I want to unit-test the Use-Cases (which call Repositories, which call Data-Sources, so on and so on) against mocked API-data to make sure that the call-and-response-flow works throughout all layers (leaving the UI aside - will be covered in UI- & E2E-Tests).
Problem/Question:
When unit-testing a Use-Cases, there are multiple API-calls involved (for example the first one to refresh an access token and the second one to actually get the desired content). Therefore, I need a way define which responses should be returned for which requests.
So, this is my test case to get available offers from the marketplace:
Test-Result:
The result of this is the following error being thrown in the OfferRepository:
What should happen:
By calling the
GetAvailableOffers
-Use-Case, theBlueprintOffersAPIClient
requests a new valid access token. For this, the first Promise should be received. After that, all available offers should be fetched and the second Promise should be received.Specific question:
How can I specify mocked responses for URLs/individual requests, so that when running my test-case my token-refresh-request receives the
/connect/authorize
mocked response, but my get-available-offers-request receives the mocked response for/api/Offers
?The text was updated successfully, but these errors were encountered: