Skip to content

Commit

Permalink
test: use-request plugin unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonYong committed May 12, 2024
1 parent 7bf2e7c commit 0dcc958
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/hooks/src/useRequest/__tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const useFormatterPlugin: UseRequestPlugin<
{
formatter?: (params?: { name: string; age: number }) => any
}
> = (fetchInstance, { formatter }) => {
> = (fetchInstance, { pluginOptions }) => {
return {
onSuccess: () => {
fetchInstance.setData(formatter?.(fetchInstance.state.data), 'data')
fetchInstance.setData(pluginOptions?.formatter?.(fetchInstance.state.data), 'data')
},
}
}
Expand All @@ -37,12 +37,14 @@ describe('useRequest/Plugin', () => {
useRequest(
() => getUsername(),
{
formatter: (data: any) => {
return {
name: `${data.name} - plugins update`,
age: 20,
}
},
pluginOptions: {
formatter: (data) => {
return {
name: `${data?.name} - plugins update`,
age: 20,
}
},
}
},
[useFormatterPlugin],
),
Expand Down

0 comments on commit 0dcc958

Please sign in to comment.