@@ -153,16 +153,30 @@ describe('Rule - Require-usecallback', () => {
153153 errors : [ { messageId : "usememo-const" } ] ,
154154 } ,
155155 {
156- code : `const Component = () => {
156+ code : `
157+ const Component = () => {
157158 return <Child prop={() => {}} />;
158159 }` ,
159160 errors : [ { messageId : "function-usecallback-props" } ] ,
161+ output : `import { useCallback } from 'react';
162+
163+ const Component = () => {
164+ const prop = useCallback(() => {}, []);
165+ return <Child prop={prop} />;
166+ }` ,
160167 } ,
161168 {
162- code : `const Component = () => {
169+ code : `
170+ const Component = () => {
163171 return <Child prop={() => []} />;
164172 }` ,
165173 errors : [ { messageId : "function-usecallback-props" } ] ,
174+ output : `import { useCallback } from 'react';
175+
176+ const Component = () => {
177+ const prop = useCallback(() => [], []);
178+ return <Child prop={prop} />;
179+ }` ,
166180 } ,
167181 {
168182 code : `class Component {
@@ -259,6 +273,47 @@ describe('Rule - Require-usecallback', () => {
259273 }` ,
260274 errors : [ { messageId : "function-usecallback-props" } , { messageId : "function-usecallback-props" } ] ,
261275 } ,
276+ {
277+ code : `
278+ const Component = () => {
279+ const myFn = async function test() {};
280+ return <Child prop={myFn} />;
281+ }` ,
282+ output : `import { useCallback } from 'react';
283+
284+ const Component = () => {
285+ const myFn = useCallback(async () => {}, []);
286+ return <Child prop={myFn} />;
287+ }` ,
288+ errors : [ { messageId : "function-usecallback-props" } ] ,
289+ } ,
290+ {
291+ code : `
292+ const Component = () => {
293+ const myFn = async () => [];
294+ return <Child prop={myFn} />;
295+ }` ,
296+ output : `import { useCallback } from 'react';
297+
298+ const Component = () => {
299+ const myFn = useCallback(async () => [], []);
300+ return <Child prop={myFn} />;
301+ }` ,
302+ errors : [ { messageId : "function-usecallback-props" } ] ,
303+ } ,
304+ {
305+ code : `
306+ const Component = () => {
307+ return <Child prop={async () => []} />;
308+ }` ,
309+ output : `import { useCallback } from 'react';
310+
311+ const Component = () => {
312+ const prop = useCallback(async () => [], []);
313+ return <Child prop={prop} />;
314+ }` ,
315+ errors : [ { messageId : "function-usecallback-props" } ] ,
316+ } ,
262317 ] ,
263318 } ) ;
264319} ) ;
0 commit comments