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

enhance: Add renderDataHook export #3238

Merged
merged 1 commit into from
Oct 6, 2024
Merged

enhance: Add renderDataHook export #3238

merged 1 commit into from
Oct 6, 2024

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Oct 6, 2024

Motivation

Simplify test usage

Solution

Introduce renderDataHook(), which uses the default DataProvider to make the common case simpler.

import { renderDataHook } from '@data-client/test';

const response = {
  id: 5,
  title: 'hi ho',
  content: 'whatever',
  tags: ['a', 'best', 'react'],
};

it('useSuspense() should render the response', async () => {
  const { result, waitFor } = renderDataHook(
    () => {
      return useSuspense(ArticleResource.get, { id: 5 });
    },
    {
      initialFixtures: [
        {
          endpoint: ArticleResource.get,
          args: [{ id: 5 }],
          response,
        },
      ],
    },
  );
  expect(result.current instanceof ArticleResource).toBe(true);
  expect(result.current.title).toBe(payload.title);
});

Note: we chose to have Hook at the end of the name to make it more clear that it is rendering hooks and it shares similarity to renderHook from testing-library.

Copy link

changeset-bot bot commented Oct 6, 2024

🦋 Changeset detected

Latest commit: 6ecf67b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@data-client/test Patch
@data-client/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.94%. Comparing base (fdd3680) to head (6ecf67b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3238   +/-   ##
=======================================
  Coverage   98.94%   98.94%           
=======================================
  Files         132      132           
  Lines        2269     2269           
  Branches      467      467           
=======================================
  Hits         2245     2245           
  Misses         13       13           
  Partials       11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ntucker ntucker enabled auto-merge October 6, 2024 20:16
@ntucker ntucker merged commit 28b702d into master Oct 6, 2024
25 checks passed
@ntucker ntucker deleted the renderDataHook branch October 6, 2024 20:16
@github-actions github-actions bot mentioned this pull request Oct 6, 2024
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

Successfully merging this pull request may close these issues.

1 participant