reactive/data-client / .agents/skills/data-client-react-testing
data-client-react-testing
VerifiedTest React code that uses @data-client/react: components and hooks that fetch or change data, with mocked responses for loading, error, mutation and polling cases. Covers renderDataHook, MockResolver and fixtures.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.0 KB |
| references.json | config | 502 B |
| references/Fixtures.md | markdown | 6.3 KB |
| references/MockResolver.md | markdown | 2.2 KB |
| references/makeRenderDataHook.md | markdown | 2.5 KB |
| references/mockInitialState.md | markdown | 1.7 KB |
| references/renderDataHook.md | markdown | 9.1 KB |
| references/unit-testing-components.md | markdown | 3.5 KB |
| references/unit-testing-hooks.md | markdown | 3.9 KB |
references/MockResolver.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/core/api/MockResolver.md (react). Edit the source doc, not this file. -->
# \<MockResolver />
```typescript
function MockResolver<T>(props: {
children: React.ReactNode;
fixtures: (Fixture | Interceptor<T>)[];
getInitialInterceptorData: () => T;
}): JSX.Element;
```
\<MockResolver /> enables easy loading of fixtures to see what different network responses might look like.
This is useful for [storybook](https://dataclient.io/docs/guides/storybook) as well as component testing.
## Arguments
### fixtures
```ts
(Fixture | Interceptor<T>)[]
```
This prop specifies the [fixtures or interceptors](./Fixtures.md) to use data from. Each item represents a fetch defined by the
[Endpoint](https://dataclient.io/rest/api/Endpoint) and params. `Result` contains the JSON response expected from said fetch.
### getInitialInterceptorData
Function that initializes the `this` attribute for all interceptors.
```ts
<MockResolver
fixtures={[
{
endpoint: new RestEndpoint({
path: '/api/count/increment',
method: 'POST',
body: undefined,
}),
response() {
return {
count: (this.count = this.count + 1),
};
},
delay: () => 500 + Math.random() * 4500,
},
]}
getInitialInterceptorData={() => ({ count: 0 })}
>
{children}
</MockResolver>
```
## Example
```tsx
import { MockResolver } from '@data-client/test';
import type { Story } from '@storybook/react';
import ArticleResource from 'resources/ArticleResource';
import MyComponentToTest from 'components/MyComponentToTest';
const results = [
// fixture
{
endpoint: ArticleResource.getList,
args: [{ maxResults: 10 }] as const,
response: [
{
id: 5,
content: 'have a merry christmas',
author: 2,
contributors: [],
},
{
id: 532,
content: 'never again',
author: 23,
contributors: [5],
},
],
},
// interceptor
{
endpoint: ArticleResource.partialUpdate,
response: ({ id }, body) => ({
...body,
id,
}),
},
];
const Template: Story = () => (
<MockResolver fixtures={results}>
<MyComponentToTest />
</MockResolver>
);
export const MyStory = Template.bind({});
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |