Skip to content

Commit

Permalink
test: add test from custom filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ogustavo-pereira committed Aug 30, 2022
1 parent 7c2005d commit 59f4b42
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/ra-core/src/controller/list/useList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,39 @@ describe('<useList />', () => {
})
);
});

it('should filter array data based on the custom filter', async () => {
const callback = jest.fn();
const data = [
{ id: 1, items: ['one', 'two'] },
{ id: 2, items: ['three'] },
{ id: 3, items: 'four' },
{ id: 4, items: ['five'] },
];

render(
<UseList
data={data}
sort={{ field: 'id', order: 'ASC' }}
setCustomFilter={record => record.id > 2}
callback={callback}
/>
);

await waitFor(() => {
expect(callback).toHaveBeenCalledWith(
expect.objectContaining({
sort: { field: 'id', order: 'ASC' },
isFetching: false,
isLoading: false,
data: [
{ id: 3, items: 'four' },
{ id: 4, items: ['five'] },
],
error: undefined,
total: 2,
})
);
});
});
});

0 comments on commit 59f4b42

Please sign in to comment.