File tree Expand file tree Collapse file tree 3 files changed +14
-13
lines changed
router/programmatic-routing/components Expand file tree Collapse file tree 3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 11<template >
22 <button
33 :class =" typeClass"
4- @click =" clicked "
4+ @click =" handleClick "
55 >{{ text }}</button >
66</template >
77
@@ -12,10 +12,6 @@ export default {
1212 type: String ,
1313 default: ' '
1414 },
15- clicked: {
16- type: Function ,
17- default : () => true
18- },
1915 type: {
2016 validator : (value ) => [' primary' , ' secondary' ].includes (value),
2117 default: ' primary'
@@ -28,6 +24,11 @@ export default {
2824 }
2925 return ' button'
3026 }
27+ },
28+ methods: {
29+ handleClick (e ) {
30+ this .$emit (' click' )
31+ }
3132 }
3233}
3334 </script >
Original file line number Diff line number Diff line change 11<template >
22 <div >
33 <div >You are home</div >
4- <button data-testid =" go-to-about" @click =" goToAbout" >About</button >
4+ <button
5+ data-testid =" go-to-about"
6+ @click =" goToAbout" >About</button >
57 </div >
68</template >
79
@@ -14,4 +16,3 @@ export default {
1416 }
1517}
1618 </script >
17-
Original file line number Diff line number Diff line change @@ -6,18 +6,17 @@ afterEach(cleanup)
66test ( 'renders button with text' , ( ) => {
77 const buttonText = "Click me; I'm sick"
88 const { getByText } = render ( SimpleButton , {
9- props : { text : buttonText , clicked : ( ) => true }
9+ props : { text : buttonText }
1010 } )
1111
1212 getByText ( buttonText )
1313} )
1414
15- test ( 'clicked prop is called when button is clicked' , ( ) => {
16- const clicked = jest . fn ( )
15+ test ( 'click event is emitted when button is clicked' , ( ) => {
1716 const text = 'Click me'
18- const { getByText } = render ( SimpleButton , {
19- props : { text, clicked }
17+ const { getByText, emitted } = render ( SimpleButton , {
18+ props : { text }
2019 } )
2120 fireEvent . click ( getByText ( text ) )
22- expect ( clicked ) . toBeCalled ( )
21+ expect ( emitted ( ) . click ) . toHaveLength ( 1 )
2322} )
You can’t perform that action at this time.
0 commit comments