Skip to content

Commit e615376

Browse files
authored
Merge pull request #25 from afontcu/master
Make button test use event emitters
2 parents 3446920 + 99b1e32 commit e615376

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

tests/__tests__/components/Button.vue

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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>

tests/__tests__/router/programmatic-routing/components/Home.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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-

tests/__tests__/simple-button.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ afterEach(cleanup)
66
test('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
})

0 commit comments

Comments
 (0)