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/mockInitialState.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/core/api/mockInitialState.md (react). Edit the source doc, not this file. -->
# mockInitialState()
```typescript
function mockInitialState(results: Fixture[]): State;
```
`mockInitialState()` makes it easy to construct prefill the cache with [fixtures](./Fixtures.md). It's
used in [\<MockResolver />](./MockResolver.md) to process the results prop. However, this
can also be useful to send into a normal provider when testing more complete flows
that need to handle `dispatches` (and thus fetch).
### Arguments
#### results
```typescript
export type Fixture = SuccessFixture | ErrorFixture;
```
This prop specifies the [fixtures](./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.
This can be used as the initialState prop for [\<DataProvider />](https://dataclient.io/docs/api/DataProvider)
## Example
```ts title="fixtures.ts"
import ArticleResource from 'resources/ArticleResource';
export const results = [
{
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],
},
],
},
];
```
```tsx
import { DataProvider } from '@data-client/react';
import { mockInitialState } from '@data-client/test';
import MyComponentToTest from 'components/MyComponentToTest';
import { results } from './fixtures';
<DataProvider initialState={mockInitialState(results)}>
<MyComponentToTest />
</DataProvider>;
```
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 |