0.14.16 • Published 8 months ago
@data-client/test v0.14.16
Features
Usage
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,
})
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: [],
};
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>
);
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);
});
0.14.16
8 months ago
0.14.10
10 months ago
0.12.8
1 year ago
0.13.0
12 months ago
0.14.0
11 months ago
0.12.12
1 year ago
0.12.13
1 year ago
0.12.3
1 year ago
0.12.1
1 year ago
0.12.0
1 year ago
0.11.5
1 year ago
0.11.4
1 year ago
0.11.0
1 year ago
0.10.0
1 year ago
0.9.2
2 years ago
0.9.0
2 years ago
0.8.0
2 years ago
0.3.1
2 years ago
0.3.0
2 years ago
1.0.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago