forked from DanSnow/vue-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.spec.js
60 lines (52 loc) · 1.35 KB
/
example.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import VueRecaptcha from '../../src'
import { mount } from 'avoriaz'
const WIDGET_ID = 'widgetId'
function createMock () {
return {
render: jest.fn(function (ele, options) {
// Save the callback
this._verify = options.callback
this._expire = options['expired-callback']
return WIDGET_ID
}),
execute: jest.fn(function () {
this._verify()
}),
reset: jest.fn()
}
}
describe('Example spec', () => {
let wrapper
let verify
let expired
beforeEach(() => {
window.grecaptcha = createMock()
verify = jest.fn()
expired = jest.fn()
wrapper = mount(VueRecaptcha, {
propsData: { sitekey: 'sitekey' }
})
wrapper.vm.$on('verify', verify)
wrapper.vm.$on('expired', expired)
})
it('Should render recaptcha', () => {
expect(window.grecaptcha.render).toBeCalled()
expect(wrapper.vm.$widgetId).toBe(WIDGET_ID)
})
it('Should call execute', () => {
wrapper.vm.execute()
expect(window.grecaptcha.execute).toBeCalledWith(WIDGET_ID)
})
it('Should call reset', () => {
wrapper.vm.reset()
expect(window.grecaptcha.reset).toBeCalledWith(WIDGET_ID)
})
it('Should emit verify', () => {
window.grecaptcha._verify()
expect(verify).toBeCalled()
})
it('Should emit expired', () => {
window.grecaptcha._expire()
expect(expired).toBeCalled()
})
})