mirror of https://github.com/sveltejs/svelte
				
				
				
			Merge pull request #2150 from sveltejs/gh-2149
	
		
	
				
					
				
			allow event handlers to come from destructured var declarationspull/2153/head
						commit
						ac38a286e6
					
				@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					export default {
 | 
				
			||||||
 | 
						html: `
 | 
				
			||||||
 | 
							<button>clicked: false</button>
 | 
				
			||||||
 | 
						`,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						async test({ assert, component, target, window }) {
 | 
				
			||||||
 | 
							const button = target.querySelector('button');
 | 
				
			||||||
 | 
							const event = new window.MouseEvent('click');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							await button.dispatchEvent(event);
 | 
				
			||||||
 | 
							assert.htmlEqual(target.innerHTML, `
 | 
				
			||||||
 | 
								<button>clicked: true</button>
 | 
				
			||||||
 | 
							`);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					<script>
 | 
				
			||||||
 | 
						function get_handlers() {
 | 
				
			||||||
 | 
							return {
 | 
				
			||||||
 | 
								handle_click: () => {
 | 
				
			||||||
 | 
									clicked = true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						let clicked = false;
 | 
				
			||||||
 | 
						const { handle_click } = get_handlers();
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<button on:click={handle_click}>
 | 
				
			||||||
 | 
						clicked: {clicked}
 | 
				
			||||||
 | 
					</button>
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue