Skip to content

Commit dc35bf0

Browse files
chore(button-close): add testing for button-close click handlers (bootstrap-vue#1455)
1 parent c26b2f7 commit dc35bf0

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/components/button/button-close.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,28 @@ describe('button-close', async () => {
6262
expect(btn.disabled).toBe(true)
6363
expect(spy).not.toHaveBeenCalled()
6464
})
65+
66+
it('calls click handlers bound by its parent', async () => {
67+
const { app } = window
68+
const $btn = app.$refs.handlers
69+
const spy1 = jest.fn()
70+
const spy2 = jest.fn()
71+
app.spies.push(spy1, spy2)
72+
73+
$btn.click()
74+
expect(spy1).toHaveBeenCalled()
75+
expect(spy2).toHaveBeenCalled()
76+
})
77+
78+
it('does not call click handlers bound by its parent when disabled', async () => {
79+
const { app } = window
80+
const $btn = app.$refs.handlersDisabled
81+
const spy1 = jest.fn()
82+
const spy2 = jest.fn()
83+
app.spies.push(spy1, spy2)
84+
85+
$btn.click()
86+
expect(spy1).not.toHaveBeenCalled()
87+
expect(spy2).not.toHaveBeenCalled()
88+
})
6589
})

src/components/button/fixtures/button-close.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<b-button-close ref="slot">close</b-button-close>
44
<b-button-close ref="disabled" disabled></b-button-close>
55
<b-button-close ref="variant" text-variant="primary"></b-button-close>
6+
<b-button-close ref="handlers" @click="handleClick"></b-button-close>
7+
<b-button-close ref="handlersDisabled" disabled @click="handleClick"></b-button-close>
68
</div>
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
window.app = new Vue({
2-
el: '#app'
2+
el: '#app',
3+
data: {
4+
spies: []
5+
},
6+
methods: {
7+
handleClick () {
8+
this.spies.forEach(spy => spy.apply(undefined, arguments))
9+
}
10+
}
311
})

0 commit comments

Comments
 (0)