Skip to content

Unable to get data from mocked HttpClient during OnInitializedAsync #255

Answered by egil
daveabrock asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Dave

Thanks for the kind words.

The HttpClient mock from the docs is not really battle hardened, so I cannot guarantee that it behaves correctly in all scenarios, and its shown more as proof-of-concept. Anyway, disclaimer aside, it looks as if you are setting up the mock to handle /api/image but in the component you are querying for "api/image. That might be it.

Otherwise your test looks fine. WaitForState before WaitForAssertion wont make a difference.

Related, I do advice not to depend explicitly on HttpClient in your components. Create an abstraction instead, e.g. IImageStore. That will not only make writing tests much easier, but also allow you to add caching and other things down …

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@mrakestraw-bbins
Comment options

@egil
Comment options

@mrakestraw-bbins
Comment options

@egil
Comment options

@mrakestraw-bbins
Comment options

Answer selected by egil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #255 on November 12, 2020 08:04.