From 7f8a15e2c7e4753f4b5dfb29d2405db726823a6b Mon Sep 17 00:00:00 2001 From: Marco Moretti Date: Sat, 13 Jun 2020 23:22:25 +0200 Subject: [PATCH] fix: typescript definitions for suggestions (#630) * fix: fix typescript definitions for suggestions * fix: add lowercase methods and make variant optional --- src/suggestions.js | 2 +- types/suggestions.d.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/suggestions.js b/src/suggestions.js index 69d25139..1e3ebb74 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -76,7 +76,7 @@ function canSuggest(currentMethod, requestedMethod, data) { ) } -export function getSuggestedQuery(element, variant, method) { +export function getSuggestedQuery(element, variant = 'get', method) { // don't create suggestions for script and style elements if (element.matches(DEFAULT_IGNORE_TAGS)) { return undefined diff --git a/types/suggestions.d.ts b/types/suggestions.d.ts index f574f344..e10fcb02 100644 --- a/types/suggestions.d.ts +++ b/types/suggestions.d.ts @@ -3,4 +3,34 @@ export interface Suggestion { toString(): string } -export function getSuggestedQuery(element: HTMLElement): Suggestion | undefined +export type Variant = + | 'get' + | 'getAll' + | 'query' + | 'queryAll' + | 'find' + | 'findAll' + +export type Method = + | 'Role' + | 'role' + | 'LabelText' + | 'labeltext' + | 'PlaceholderText' + | 'placeholdertext' + | 'Text' + | 'text' + | 'DisplayValue' + | 'displayvalue' + | 'AltText' + | 'alttext' + | 'Title' + | 'title' + | 'TestId' + | 'testtd' + +export function getSuggestedQuery( + element: HTMLElement, + variant?: Variant, + method?: Method, +): Suggestion | undefined