forked from DanSnow/vue-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.spec.js
55 lines (46 loc) · 1.25 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
import { VueRecaptcha } from '../../src'
import { mount } from '@vue/test-utils'
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
beforeEach(() => {
window.grecaptcha = createMock()
wrapper = mount(VueRecaptcha, {
props: { sitekey: 'sitekey' },
})
})
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(wrapper.emitted('verify').length).toBe(1)
})
it('Should emit expired', () => {
window.grecaptcha._expire()
expect(wrapper.emitted('expired').length).toBe(1)
})
})