Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Unit tests - Get component #18

Merged
merged 6 commits into from
Aug 6, 2018
Merged

Unit tests - Get component #18

merged 6 commits into from
Aug 6, 2018

Conversation

fabien0102
Copy link
Contributor

Why

The following of #17

Note

I've have removed the throwing inside fetch, it was a bit weird and really hard to test. In fact I wondering how it works in real world?

BTW, I think that in this context, it's not really practicle and I prefer to deal with a simple error object.

I think that the original idea was to do this:

<RestfulProvider base="https://my-awesome-api.fake">
  <Get path="">
    {(_, {}, { refetch }) => (
      <Button
        onClick={() => {
          refetch()
            .then()
            .catch();
        }}
      />
    )}
  </Get>
</RestfulProvider>;

But it's more natural to deal with error in the first level like this:

<RestfulProvider base="https://my-awesome-api.fake">
  <Get path="">
    {(_, { error }, { refetch }) =>
      error ? (
        "error!"
      ) : (
        <Button
          onClick={() => {
            refetch();
          }}
        />
      )
    }
  </Get>
</RestfulProvider>;

And, because we use this.fetch for the refresh and the "initial fetch" it's really hard to catch an error for this first fetch 😉

@fabien0102 fabien0102 added the enhancement New feature or request label Aug 5, 2018
@fabien0102 fabien0102 requested a review from TejasQ August 5, 2018 18:22
@TejasQ TejasQ merged commit 53dc5f7 into next Aug 6, 2018
@fabien0102 fabien0102 deleted the unit-tests branch August 8, 2018 08:11
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants