@@ -273,4 +273,75 @@ describe('add_autofixers_issues', () => {
273273			} , 
274274		) ; 
275275	} ) ; 
276+ 
277+ 	describe ( 'derived_with_function' ,  ( )  =>  { 
278+ 		it ( `should add suggestions when using a function as the first argument to $derived` ,  ( )  =>  { 
279+ 			const  content  =  run_autofixers_on_code ( ` 
280+ 			<script> 
281+ 				const value = $derived(() => { 
282+ 					return 43; 
283+ 				}); 
284+ 			</script>` ) ; 
285+ 
286+ 			expect ( content . suggestions . length ) . toBeGreaterThanOrEqual ( 1 ) ; 
287+ 			expect ( content . suggestions ) . toContain ( 
288+ 				'You are passing a function to $derived when declaring "value" but $derived expects an expression. You can use $derived.by instead.' , 
289+ 			) ; 
290+ 		} ) ; 
291+ 
292+ 		it ( `should add suggestions when using a function as the first argument to $derived in classes` ,  ( )  =>  { 
293+ 			const  content  =  run_autofixers_on_code ( ` 
294+ 			<script> 
295+ 				class Double { 
296+ 					value = $derived(() => 43); 
297+ 				} 
298+ 			</script>` ) ; 
299+ 
300+ 			expect ( content . suggestions . length ) . toBeGreaterThanOrEqual ( 1 ) ; 
301+ 			expect ( content . suggestions ) . toContain ( 
302+ 				'You are passing a function to $derived when declaring "value" but $derived expects an expression. You can use $derived.by instead.' , 
303+ 			) ; 
304+ 		} ) ; 
305+ 
306+ 		it ( `should add suggestions when using a function as the first argument to $derived in classes constructors` ,  ( )  =>  { 
307+ 			const  content  =  run_autofixers_on_code ( ` 
308+ 			<script> 
309+ 				class Double { 
310+ 					value; 
311+ 
312+ 					constructor(){ 
313+ 						this.value = $derived(function() { return 44; }); 
314+ 					} 
315+ 				} 
316+ 			</script>` ) ; 
317+ 
318+ 			expect ( content . suggestions . length ) . toBeGreaterThanOrEqual ( 1 ) ; 
319+ 			expect ( content . suggestions ) . toContain ( 
320+ 				'You are passing a function to $derived when declaring "value" but $derived expects an expression. You can use $derived.by instead.' , 
321+ 			) ; 
322+ 		} ) ; 
323+ 
324+ 		it ( `should add suggestions when using a function as the first argument to $derived without the declaring part if it's not an identifier` ,  ( )  =>  { 
325+ 			const  content  =  run_autofixers_on_code ( ` 
326+ 			<script> 
327+ 				const { destructured } = $derived(() => 43); 
328+ 			</script>` ) ; 
329+ 
330+ 			expect ( content . suggestions . length ) . toBeGreaterThanOrEqual ( 1 ) ; 
331+ 			expect ( content . suggestions ) . toContain ( 
332+ 				'You are passing a function to $derived but $derived expects an expression. You can use $derived.by instead.' , 
333+ 			) ; 
334+ 		} ) ; 
335+ 
336+ 		it ( `should add suggestions when using a function as the first argument to $derived.by` ,  ( )  =>  { 
337+ 			const  content  =  run_autofixers_on_code ( ` 
338+ 			<script> 
339+ 				const { destructured } = $derived.by(() => 43); 
340+ 			</script>` ) ; 
341+ 
342+ 			expect ( content . suggestions ) . not . toContain ( 
343+ 				'You are passing a function to $derived but $derived expects an expression. You can use $derived.by instead.' , 
344+ 			) ; 
345+ 		} ) ; 
346+ 	} ) ; 
276347} ) ; 
0 commit comments