File tree 3 files changed +14
-13
lines changed
router/programmatic-routing/components
3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<button
3
3
:class =" typeClass"
4
- @click =" clicked "
4
+ @click =" handleClick "
5
5
>{{ text }}</button >
6
6
</template >
7
7
@@ -12,10 +12,6 @@ export default {
12
12
type: String ,
13
13
default: ' '
14
14
},
15
- clicked: {
16
- type: Function ,
17
- default : () => true
18
- },
19
15
type: {
20
16
validator : (value ) => [' primary' , ' secondary' ].includes (value),
21
17
default: ' primary'
@@ -28,6 +24,11 @@ export default {
28
24
}
29
25
return ' button'
30
26
}
27
+ },
28
+ methods: {
29
+ handleClick (e ) {
30
+ this .$emit (' click' )
31
+ }
31
32
}
32
33
}
33
34
</script >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
3
<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 >
5
7
</div >
6
8
</template >
7
9
@@ -14,4 +16,3 @@ export default {
14
16
}
15
17
}
16
18
</script >
17
-
Original file line number Diff line number Diff line change @@ -6,18 +6,17 @@ afterEach(cleanup)
6
6
test ( 'renders button with text' , ( ) => {
7
7
const buttonText = "Click me; I'm sick"
8
8
const { getByText } = render ( SimpleButton , {
9
- props : { text : buttonText , clicked : ( ) => true }
9
+ props : { text : buttonText }
10
10
} )
11
11
12
12
getByText ( buttonText )
13
13
} )
14
14
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' , ( ) => {
17
16
const text = 'Click me'
18
- const { getByText } = render ( SimpleButton , {
19
- props : { text, clicked }
17
+ const { getByText, emitted } = render ( SimpleButton , {
18
+ props : { text }
20
19
} )
21
20
fireEvent . click ( getByText ( text ) )
22
- expect ( clicked ) . toBeCalled ( )
21
+ expect ( emitted ( ) . click ) . toHaveLength ( 1 )
23
22
} )
You can’t perform that action at this time.
0 commit comments