webdriverio/__mocks__/webdriverio.ts

33 lines
965 B
TypeScript
Raw Permalink Normal View History

2022-05-19 01:06:14 -08:00
import { vi } from 'vitest'
const SevereServiceErrorImport = await vi.importActual('../packages/webdriverio/src/utils/SevereServiceError') as { default: any }
const getWdioMock = () => {
const mock = {
2022-05-19 01:06:14 -08:00
$: vi.fn(),
$$: vi.fn(),
debug: vi.fn(),
on: vi.fn(),
sessionId: 'fakeid',
addCommand: vi.fn(),
overwriteCommand: vi.fn(),
2022-05-19 01:06:14 -08:00
react$: vi.fn(),
react$$: vi.fn(),
custom$: vi.fn(),
deleteSession: vi.fn()
}
mock.deleteSession.mockReturnValue(Promise.resolve(mock))
return mock
2018-11-12 12:31:33 -09:00
}
2022-05-19 01:06:14 -08:00
export const attach = vi.fn().mockImplementation(() => (getWdioMock()))
export const remote = vi.fn().mockImplementation(() => {
if ((global as any).throwRemoteCall) {
throw new Error('boom')
}
return getWdioMock()
})
2022-05-19 01:06:14 -08:00
export const multiremote = vi.fn().mockImplementation(() => (getWdioMock()))
export const SevereServiceError = SevereServiceErrorImport.default