File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
packages/svelte/tests/runtime-runes/samples/event-handler-invalid-values Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ import { assertType } from 'vitest' ;
2+ import { test } from '../../test' ;
3+
4+ export default test ( {
5+ mode : [ 'client' ] ,
6+
7+ compileOptions : {
8+ dev : true
9+ } ,
10+
11+ test ( { assert, target, warnings, logs } ) {
12+ /** @type {any } */
13+ let error = null ;
14+
15+ const handler = ( /** @type {any } */ e ) => {
16+ error = e . error ;
17+ e . stopImmediatePropagation ( ) ;
18+ } ;
19+
20+ window . addEventListener ( 'error' , handler , true ) ;
21+
22+ const [ b1 , b2 , b3 ] = target . querySelectorAll ( 'button' ) ;
23+
24+ b1 . click ( ) ;
25+ assert . deepEqual ( logs , [ ] ) ;
26+ assert . equal ( error , null ) ;
27+
28+ error = null ;
29+ logs . length = 0 ;
30+
31+ b2 . click ( ) ;
32+ assert . deepEqual ( logs , [ 'clicked' ] ) ;
33+ assert . equal ( error , null ) ;
34+
35+ error = null ;
36+ logs . length = 0 ;
37+
38+ b3 . click ( ) ;
39+ assert . deepEqual ( logs , [ ] ) ;
40+ assert . deepEqual ( warnings , [
41+ '`click` handler at main.svelte:10:17 should be a function. Did you mean to add a leading `() =>`?'
42+ ] ) ;
43+ assert . isNotNull ( error ) ;
44+ assert . match ( error . message , / i s n o t a f u n c t i o n / ) ;
45+
46+ window . removeEventListener ( 'error' , handler , true ) ;
47+ }
48+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ let ignore = null ;
3+ let handler = () => console .log (" clicked" );
4+ let bad = " invalid" ;
5+
6+ </script >
7+
8+ <button onclick ={ignore }>click</button >
9+ <button onclick ={handler }>click</button >
10+ <button onclick ={bad }>click</button >
You can’t perform that action at this time.
0 commit comments