# @data-client/test

> Testing utilities for Data Client

Latest version **0.18.0** (published 2026-05-01) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @data-client/test
pnpm add @data-client/test
yarn add @data-client/test
bun add @data-client/test
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.18.0 |
| Published | 2026-05-01 |
| First published | 2023-07-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^12.17 \|\| ^13.7 \|\| >=14 |
| Dependencies | 3 |
| Unpacked size | 356.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2034 |
| Author | Nathaniel Tucker <me@ntucker.me> (https://github.com/ntucker) |
| Maintainers | ntucker |
| Keywords | testing, storybook, hooks, react, data, cache, flux, suspense, fetch, hook, networking, concurrent mode, typescript, redux, data fetching, data cache, normalized cache, async, swr |

## Links

- npm: https://www.npmjs.com/package/@data-client/test
- Repository: https://github.com:reactive/data-client
- Homepage: https://dataclient.io/docs/guides/storybook
- Issues: https://github.com/reactive/data-client/issues
- Funding: https://github.com/sponsors/ntucker
- npm.io page: https://npm.io/package/@data-client/test

## Dependencies (3)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.20.0
- [@testing-library/dom](https://npm.io/package/@testing-library/dom.md) ^10.1.0
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^16.0.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.18.0 (latest) — 2026-05-01
- 0.15.0-beta-20251022142546-a457d1596871fb28f1a91f2531cc259db4d55a9c (beta) — 2025-10-22
- 0.16.0 — 2026-03-31
- 0.15.3 — 2026-01-06
- 0.15.0 — 2026-01-05
- 0.15.0-beta-20251006024044-92bd01c4976f2921993b8c9f1e4dbb87af87ba7b — 2025-10-06
- 0.14.22 — 2025-03-01
- 0.14.21 — 2025-02-27
- 0.14.20 — 2025-02-26
- 0.14.19 — 2025-02-24
- 0.14.17 — 2024-11-25
- 0.14.16 — 2024-10-13
- 0.14.10 — 2024-08-14
- 0.14.0 — 2024-07-13
- 0.13.0 — 2024-06-17
- … 22 more at https://npm.io/package/@data-client/test/versions

## README

# ![Data Client Testing](https://raw.githubusercontent.com/reactive/data-client/master/packages/core/data_client_logo_and_text.svg?sanitize=true)

[![Coverage Status](https://img.shields.io/codecov/c/gh/reactive/data-client/master.svg?style=flat-square)](https://app.codecov.io/gh/reactive/data-client?branch=master)

<div align="center">

**[🏁Guides](https://dataclient.io/docs/guides/storybook)** &nbsp;|&nbsp; [🏁API Reference](https://dataclient.io/docs/api/Fixtures)

</div>

## Features

- [x] [Mocking for Storybook](https://dataclient.io/docs/guides/storybook)
- [x] [Fixtures for component tests](https://dataclient.io/docs/guides/unit-testing-components)
- [x] [Hook unit testing utility](https://dataclient.io/docs/guides/unit-testing-hooks)

## Usage

<details>
<summary><b>Resource</b></summary>

```typescript
import { resource, Entity } from '@data-client/rest';

export default class Article extends Entity {
  id = '';
  content = '';
  author: number | null = null;
  contributors: number[] = [];
}
export const ArticleResource = resource({
  urlRoot: 'http://test.com',
  path: '/article/:id',
  schema: Article,
})
```

</details>

<details>
<summary><b>Fixtures</b></summary>

```typescript
export default {
  full: [
    {
      endpoint: ArticleResource.getList,
      args: [{ maxResults: 10 }],
      response: [
        {
          id: 5,
          content: 'have a merry christmas',
          author: 2,
          contributors: [],
        },
        {
          id: 532,
          content: 'never again',
          author: 23,
          contributors: [5],
        },
      ],
    },
  ],
  empty: [
    {
      endpoint: ArticleResource.getList,
      args: [{ maxResults: 10 }],
      response: [],
    },
  ],
  error: [
    {
      endpoint: ArticleResource.getList,
      args: [{ maxResults: 10 }],
      response: { message: 'Bad request', status: 400, name: 'Not Found' },
      error: true,
    },
  ],
  loading: [],
};
```

</details>

<details open><summary><b>Storybook</b></summary>

```typescript
import { MockResolver } from '@data-client/test';
import type { Fixture } from '@data-client/test';
import { Story } from '@storybook/react/types-6-0';

import ArticleList from 'ArticleList';
import options from './fixtures';

export default {
  title: 'Pages/ArticleList',
  component: ArticleList,
};

export const FullArticleList = ({ result }) => (
  <MockResolver fixtures={options[result]}>
    <ArticleList maxResults={10} />
  </MockResolver>
);
```

</details>

<details open><summary><b>Hook Unit Test</b></summary>

```typescript
import { DataProvider } from '@data-client/react';
import { renderDataHook } from '@data-client/test';
import options from './fixtures';

it('should resolve list', async () => {
  const { result } = renderDataHook(
    () => {
      return useSuspense(ArticleResource.getList, {
        maxResults: 10,
      });
    },
    { initialFixtures: options.full },
  );
  expect(result.current).toBeDefined();
  expect(result.current.length).toBe(2);
  expect(result.current[0]).toBeInstanceOf(ArticleResource);
});

it('should throw errors on bad network', async () => {
  const { result } = renderDataHook(
    () => {
      return useSuspense(ArticleResource.getList, {
        maxResults: 10,
      });
    },
    { initialFixtures: options.error },
  );
  expect(result.error).toBeDefined();
  expect((result.error as any).status).toBe(400);
});
```

</details>

---
_Source: https://npm.io/package/@data-client/test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
