Skip to content

Commit bf24dff

Browse files
committed
fix: type error
1 parent 8ec2061 commit bf24dff

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/types/smartcaptcha.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,17 @@ export interface SmartCaptcha {
6767
reset: (widgetId?: WidgetId) => void
6868

6969
destroy: (widgetId?: WidgetId) => void
70-
71-
subscribe(widgetId: WidgetId, event: 'success', callback: SuccessEventCallback): () => void
72-
subscribe(widgetId: WidgetId, event: 'javascript-error', callback: JavascriptErrorEventCallback): () => void
73-
subscribe(widgetId: WidgetId, event: Exclude<SubscribeEvent, 'success', 'javascript-error'>, callback: BaseEventCallback): () => void
70+
71+
/**
72+
* TODO types
73+
*
74+
* if event === 'success', cb will be SuccessEventCallback
75+
* if event === 'javascript-error', cb will be JavascriptErrorEventCallback
76+
* otherwise BaseEventCallback
77+
*/
78+
subscribe: (
79+
widgetId: WidgetId,
80+
event: SubscribeEvent,
81+
callback: (...args: unknown) => void
82+
) => void
7483
}

tests/captcha.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
22
import { mount } from '@vue/test-utils'
33
import DummyCaptchaWithNoProps from './components/DummyCaptchaWithNoProps.vue'
4-
import type { SuccessEventCallback } from '@/types/smartcaptcha'
4+
import type { Token } from '@/types/smartcaptcha'
55
import { nextTick } from 'vue'
66

77
const sleep = async (time = 200) => await new Promise(resolve => setTimeout(resolve, time)) // Wait longer than the component timeout
@@ -10,17 +10,16 @@ beforeEach(() => {
1010
window.smartCaptcha = {
1111
render: vi.fn(() => 1234),
1212
getResponse: vi.fn(() => '__token'),
13-
subscribe: vi.fn((id, event, cb) => {
14-
// mock token on success
13+
subscribe: vi.fn((_widgetId, event, cb) => {
1514
if (event === 'success') {
16-
(cb as SuccessEventCallback)('__token')
15+
cb('__token')
1716
}
1817

1918
if (event === 'challenge-hidden') {
2019
cb()
2120
}
2221

23-
return () => {}
22+
return {}
2423
}),
2524
execute: vi.fn(),
2625
destroy: vi.fn(),

0 commit comments

Comments
 (0)