forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selector-error-ctor-callback.ts
29 lines (24 loc) · 1.17 KB
/
selector-error-ctor-callback.ts
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
import { AutomationErrorCtor } from '../types';
import { FnInfo, SelectorErrorCb } from '../../client/driver/command-executors/client-functions/types';
import * as Errors from './index';
export function getInvisibleErrorCtor (elementName?: string): AutomationErrorCtor | string {
return !elementName ? 'ActionElementIsInvisibleError' : {
name: 'ActionAdditionalElementIsInvisibleError',
firstArg: elementName,
};
}
export function getNotFoundErrorCtor (elementName?: string): AutomationErrorCtor | string {
return !elementName ? 'ActionElementNotFoundError' : {
name: 'ActionAdditionalElementNotFoundError',
firstArg: elementName,
};
}
export function getCannotObtainInfoErrorCtor (): AutomationErrorCtor | string {
return 'CannotObtainInfoForElementSpecifiedBySelectorError';
}
export default function createErrorCtorCallback (errCtor: AutomationErrorCtor | string): SelectorErrorCb {
// @ts-ignore
const Error = typeof errCtor === 'string' ? Errors[errCtor] : Errors[errCtor.name];
const firstArg = typeof errCtor === 'string' ? null : errCtor.firstArg;
return (fn: FnInfo | null) => new Error(firstArg, fn);
}