fix: errors in tests

This commit is contained in:
chenos 2022-02-13 20:36:53 +08:00
parent ce3daba61d
commit ae43b1e99c
11 changed files with 73 additions and 71 deletions

View File

@ -1,7 +1,8 @@
import { render } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { RouteSwitchProvider, RouteSwitch } from '../';
import { render } from '@testing-library/react';
import { RouteSwitch } from '../RouteSwitch';
import { RouteSwitchProvider } from '../RouteSwitchProvider';
const Home = () => <h1>Home</h1>;
const About = () => <h1>About</h1>;

View File

@ -1,6 +1,7 @@
export * from './antd';
export * from './context';
export * from './hooks';
export * from './RouteSwitch';
export * from './RouteSwitchProvider';
export * from './types';
export * from './antd';

View File

@ -1,8 +1,8 @@
import { formatMomentValue, usePrefixCls } from '@formily/antd/esm/__builtins__';
import { formatMomentValue, usePrefixCls } from '@formily/antd/lib/__builtins__';
import { isArr } from '@formily/shared';
import type {
DatePickerProps as AntdDatePickerProps,
RangePickerProps as AntdRangePickerProps,
RangePickerProps as AntdRangePickerProps
} from 'antd/lib/date-picker';
import cls from 'classnames';
import moment from 'moment';

View File

@ -1,5 +1,5 @@
import { formatMomentValue, momentable } from '@formily/antd/lib/__builtins__';
import type { DatePickerProps } from 'antd/lib/date-picker';
import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__';
export const getDefaultFormat = (props: DatePickerProps & { dateFormat: string; timeFormat: string }) => {
if (props.format) {

View File

@ -1,4 +1,4 @@
import { usePrefixCls } from '@formily/antd/esm/__builtins__';
import { usePrefixCls } from '@formily/antd/lib/__builtins__';
import { Popover } from 'antd';
import { InputProps, TextAreaProps } from 'antd/lib/input';
import cls from 'classnames';

View File

@ -1,4 +1,4 @@
import { formatMomentValue, usePrefixCls } from '@formily/antd/esm/__builtins__';
import { formatMomentValue, usePrefixCls } from '@formily/antd/lib/__builtins__';
import { isArr } from '@formily/shared';
import { TimeRangePickerProps } from 'antd/lib/time-picker';
import cls from 'classnames';

View File

@ -1,4 +1,4 @@
import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__';
import { formatMomentValue, momentable } from '@formily/antd/lib/__builtins__';
import { connect, mapProps, mapReadPretty } from '@formily/react';
import { TimePicker as AntdTimePicker } from 'antd';
import { TimePickerProps as AntdTimePickerProps, TimeRangePickerProps } from 'antd/lib/time-picker';

View File

@ -1,4 +1,4 @@
import { usePrefixCls } from '@formily/antd/esm/__builtins__';
import { usePrefixCls } from '@formily/antd/lib/__builtins__';
import { Field } from '@formily/core';
import { observer, useField } from '@formily/react';
import { isArr } from '@formily/shared';

View File

@ -1,7 +1,7 @@
import DeleteOutlined from '@ant-design/icons/DeleteOutlined';
import DownloadOutlined from '@ant-design/icons/DownloadOutlined';
import PlusOutlined from '@ant-design/icons/PlusOutlined';
import { usePrefixCls } from '@formily/antd/esm/__builtins__';
import { usePrefixCls } from '@formily/antd/lib/__builtins__';
import { connect, mapProps, mapReadPretty } from '@formily/react';
import { Button, Progress, Space, Upload as AntdUpload } from 'antd';
import cls from 'classnames';

View File

@ -1,7 +1,7 @@
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import supertest from 'supertest';
import Resourcer from '../resourcer';
import bodyParser from 'koa-bodyparser';
describe('koa middleware', () => {
it('shound work', async () => {
@ -205,7 +205,7 @@ describe('koa middleware', () => {
other: 'other1',
sort: '-id',
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
sort: '-id',
filter: {
$and: [
@ -231,7 +231,7 @@ describe('koa middleware', () => {
},
});
const response = await agent.post('/tests').send({ aa: 'aa' });
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'create',
resourceName: 'tests',
values: { col1: 'val1', aa: 'aa' },
@ -251,7 +251,7 @@ describe('koa middleware', () => {
const response = await agent.post('/resourcer/tests:create').send({
values: { aa: 'aa' },
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'create',
resourceName: 'tests',
values: { col1: 'val1', aa: 'aa' },
@ -272,7 +272,7 @@ describe('koa middleware', () => {
resourceIndex: 1,
values: { aa: 'aa' },
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
resourceIndex: 1,
actionName: 'update',
resourceName: 'tests',
@ -288,7 +288,7 @@ describe('koa middleware', () => {
});
it('get', async () => {
const response = await agent.get('/users/1/settings');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'settings',
@ -297,7 +297,7 @@ describe('koa middleware', () => {
});
it('update', async () => {
const response = await agent.post('/users/1/settings');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'settings',
@ -306,7 +306,7 @@ describe('koa middleware', () => {
});
it('destroy', async () => {
const response = await agent.delete('/users/1/settings');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'settings',
@ -323,7 +323,7 @@ describe('koa middleware', () => {
});
it('list', async () => {
const response = await agent.get('/users/1/posts');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'posts',
@ -332,7 +332,7 @@ describe('koa middleware', () => {
});
it('get', async () => {
const response = await agent.get('/users/1/posts/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'posts',
@ -342,7 +342,7 @@ describe('koa middleware', () => {
});
it('create', async () => {
const response = await agent.post('/users/1/posts');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'posts',
@ -351,7 +351,7 @@ describe('koa middleware', () => {
});
it('update', async () => {
const response = await agent.put('/users/1/posts/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'posts',
@ -361,7 +361,7 @@ describe('koa middleware', () => {
});
it('destroy', async () => {
const response = await agent.delete('/users/1/posts/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: '1',
resourceName: 'posts',
@ -379,7 +379,7 @@ describe('koa middleware', () => {
});
it('get', async () => {
const response = await agent.get('/posts/1/user');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'user',
@ -388,7 +388,7 @@ describe('koa middleware', () => {
});
it('set', async () => {
const response = await agent.post('/posts/1/user/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'user',
@ -398,7 +398,7 @@ describe('koa middleware', () => {
});
it('remove', async () => {
const response = await agent.delete('/posts/1/user');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'user',
@ -415,7 +415,7 @@ describe('koa middleware', () => {
});
it('list', async () => {
const response = await agent.get('/posts/1/tags');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -424,7 +424,7 @@ describe('koa middleware', () => {
});
it('get', async () => {
const response = await agent.get('/posts/1/tags/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -434,7 +434,7 @@ describe('koa middleware', () => {
});
it('set', async () => {
const response = await agent.post('/posts/1/tags');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -443,7 +443,7 @@ describe('koa middleware', () => {
});
it('add', async () => {
const response = await agent.post('/posts/1/tags/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -453,7 +453,7 @@ describe('koa middleware', () => {
});
it('update', async () => {
const response = await agent.put('/posts/1/tags/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -463,7 +463,7 @@ describe('koa middleware', () => {
});
it('remove', async () => {
const response = await agent.delete('/posts/1/tags/1');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'posts',
associatedIndex: '1',
resourceName: 'tags',
@ -482,7 +482,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
fields: ['id', 'col1'],
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
fields: ['id', 'col1'],
@ -500,7 +500,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
fields: ['id', 'col1'],
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
fields: ['id'],
@ -518,7 +518,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
fields: ['id', 'col1', 'password'],
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
fields: ['id', 'col1', 'password'],
@ -538,7 +538,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
fields: ['id', 'col1', 'password', 'col2'],
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
fields: ['id', 'col1', 'password', 'col2'],
@ -559,7 +559,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
appends: ['relation1'],
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
except: ['password'],
@ -576,7 +576,7 @@ describe('koa middleware', () => {
const response = await agent.get('/test1').query({
appends: 'rel1,rel2',
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
actionName: 'list',
resourceName: 'test1',
appends: ['rel1', 'rel2'],
@ -592,7 +592,7 @@ describe('koa middleware', () => {
const response = await agent.get('/users/name/posts').query({
appends: 'rel1,rel2',
});
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: 'name',
resourceName: 'posts',
@ -613,7 +613,7 @@ describe('koa middleware', () => {
},
});
const response = await agent.get('/users/name/posts');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: 'name',
resourceName: 'posts',
@ -634,7 +634,7 @@ describe('koa middleware', () => {
},
});
const response = await agent.get('/users/name/posts');
expect(response.body).toEqual({
expect(response.body).toMatchObject({
associatedName: 'users',
associatedIndex: 'name',
resourceName: 'posts',

View File

@ -24,25 +24,25 @@ describe('utils', () => {
describe('parseFields', () => {
it('plain string fields equal to only', () => {
expect(parseFields('name,age')).toEqual({
expect(parseFields('name,age')).toMatchObject({
only: ['name', 'age'],
});
});
it('plain array fields equal to only', () => {
expect(parseFields(['name', 'age'])).toEqual({
expect(parseFields(['name', 'age'])).toMatchObject({
only: ['name', 'age'],
});
});
it('only string fields equal to only', () => {
expect(parseFields({ only: 'name,age' })).toEqual({
expect(parseFields({ only: 'name,age' })).toMatchObject({
only: ['name', 'age'],
});
});
it('only array fields equal to only', () => {
expect(parseFields({ only: ['name', 'age'] })).toEqual({
expect(parseFields({ only: ['name', 'age'] })).toMatchObject({
only: ['name', 'age'],
});
});
@ -50,7 +50,7 @@ describe('utils', () => {
it('plain only and expect fields', () => {
// input as "fields=title&fields[only]=content&fields[except]=status&fields[except]=created_at"
const result = parseFields(['title', { only: 'content' }, { except: ['status', 'created_at'] }]);
expect(result).toEqual({
expect(result).toMatchObject({
only: ['title', 'content'],
except: ['status', 'created_at'],
});
@ -60,11 +60,11 @@ describe('utils', () => {
describe('mergeFields', () => {
describe('empty default', () => {
it('always contains "appends"', async () => {
expect(mergeFields({}, { only: ['col'] })).toEqual({ appends: [], only: ['col'] });
expect(mergeFields({}, { only: ['col'] })).toMatchObject({ appends: [], only: ['col'] });
});
it('appends', async () => {
expect(mergeFields({}, { only: ['col1'], appends: ['col2'] })).toEqual({ only: ['col1'], appends: ['col2'] });
expect(mergeFields({}, { only: ['col1'], appends: ['col2'] })).toMatchObject({ only: ['col1'], appends: ['col2'] });
});
});
@ -83,7 +83,7 @@ describe('utils', () => {
appends: ['col6'],
},
),
).toEqual({
).toMatchObject({
only: ['col1'],
appends: ['col6', 'col4'],
});
@ -97,7 +97,7 @@ describe('utils', () => {
path: '/posts',
method: 'GET',
});
expect(params).toEqual({ resourceName: 'posts', actionName: 'list' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'list' });
});
it('store action', () => {
@ -105,7 +105,7 @@ describe('utils', () => {
path: '/posts',
method: 'POST',
});
expect(params).toEqual({ resourceName: 'posts', actionName: 'create' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'create' });
});
it('get action', () => {
@ -113,7 +113,7 @@ describe('utils', () => {
path: '/posts/1',
method: 'GET',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1', actionName: 'get' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1', actionName: 'get' });
});
it('update action', () => {
@ -121,7 +121,7 @@ describe('utils', () => {
path: '/posts/1',
method: 'PUT',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1', actionName: 'update' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1', actionName: 'update' });
});
it('update action', () => {
@ -129,7 +129,7 @@ describe('utils', () => {
path: '/posts/1',
method: 'PATCH',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1', actionName: 'update' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1', actionName: 'update' });
});
it('delete action', () => {
@ -137,7 +137,7 @@ describe('utils', () => {
path: '/posts/1',
method: 'delete',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1', actionName: 'destroy' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1', actionName: 'destroy' });
});
it('delete action', () => {
@ -145,7 +145,7 @@ describe('utils', () => {
path: '/posts/1,2,3,4,5,6',
method: 'delete',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1,2,3,4,5,6', actionName: 'destroy' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1,2,3,4,5,6', actionName: 'destroy' });
});
it('index action', () => {
@ -153,7 +153,7 @@ describe('utils', () => {
path: '/posts/1/comments',
method: 'GET',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
associatedName: 'posts',
associatedIndex: '1',
@ -166,7 +166,7 @@ describe('utils', () => {
path: '/posts/1/comments',
method: 'POST',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
associatedName: 'posts',
associatedIndex: '1',
@ -179,7 +179,7 @@ describe('utils', () => {
path: '/posts/1/comments/1',
method: 'GET',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
resourceIndex: '1',
associatedName: 'posts',
@ -193,7 +193,7 @@ describe('utils', () => {
path: '/posts/1/comments/1',
method: 'PUT',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
resourceIndex: '1',
associatedName: 'posts',
@ -207,7 +207,7 @@ describe('utils', () => {
path: '/posts/1/comments/1',
method: 'PATCH',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
resourceIndex: '1',
associatedName: 'posts',
@ -221,7 +221,7 @@ describe('utils', () => {
path: '/posts/1/comments/1',
method: 'delete',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'comments',
resourceIndex: '1',
associatedName: 'posts',
@ -235,7 +235,7 @@ describe('utils', () => {
path: '/posts:export',
method: 'GET',
});
expect(params).toEqual({ resourceName: 'posts', actionName: 'export' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'export' });
});
it('export action', () => {
@ -243,7 +243,7 @@ describe('utils', () => {
path: '/posts:export',
method: 'POST',
});
expect(params).toEqual({ resourceName: 'posts', actionName: 'export' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'export' });
});
it('export action', () => {
@ -251,7 +251,7 @@ describe('utils', () => {
path: '/posts:export/1',
method: 'POST',
});
expect(params).toEqual({ resourceName: 'posts', resourceIndex: '1', actionName: 'export' });
expect(params).toMatchObject({ resourceName: 'posts', resourceIndex: '1', actionName: 'export' });
});
it('attach action', () => {
@ -259,7 +259,7 @@ describe('utils', () => {
path: '/posts/1/tags:attach/2',
method: 'POST',
});
expect(params).toEqual({
expect(params).toMatchObject({
resourceName: 'tags',
resourceIndex: '2',
associatedIndex: '1',
@ -278,7 +278,7 @@ describe('utils', () => {
prefix: '/api',
},
);
expect(params).toEqual({ resourceName: 'posts', actionName: 'list' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'list' });
});
it('prefix options', () => {
@ -306,7 +306,7 @@ describe('utils', () => {
},
},
);
expect(params).toEqual({ resourceName: 'posts', actionName: 'query' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'query' });
});
it('actions options', () => {
@ -314,7 +314,7 @@ describe('utils', () => {
path: '/posts:list',
method: 'GET',
});
expect(params).toEqual({ resourceName: 'posts', actionName: 'list' });
expect(params).toMatchObject({ resourceName: 'posts', actionName: 'list' });
});
it('actions options', () => {
@ -322,7 +322,7 @@ describe('utils', () => {
path: '/resourcer/user.posts:list',
method: 'GET',
});
expect(params).toEqual({ associatedName: 'user', resourceName: 'posts', actionName: 'list' });
expect(params).toMatchObject({ associatedName: 'user', resourceName: 'posts', actionName: 'list' });
});
});
});