test-drive
Advanced tools
Comparing version 0.0.33 to 0.0.34
@@ -1,1 +0,1 @@ | ||
export declare function selectDom<T extends Element>(container: T, attrName?: string): (...selectors: string[]) => T | null; | ||
export declare function selectDom(container: Element, attrName?: string): <T extends Element>(...selectors: string[]) => T | null; |
{ | ||
"name": "test-drive", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "Opinionated library for writing web component tests", | ||
@@ -43,3 +43,3 @@ "main": "./dist/src/index.js", | ||
"mocha-loader": "1.1.1", | ||
"npminject": "1.0.224", | ||
"npminject": "1.0.226", | ||
"rimraf": "2.6.1", | ||
@@ -46,0 +46,0 @@ "typescript": "2.1.6", |
@@ -171,1 +171,2 @@ # Test Drive | ||
``` | ||
@@ -1,14 +0,14 @@ | ||
export function selectDom<T extends Element>(container: T, attrName: string = 'data-automation-id'): (...selectors: string[]) => T | null { | ||
export function selectDom(container: Element, attrName: string = 'data-automation-id') { | ||
function select(parentElement: T, ...selectors: string[]): T | null { | ||
function select<T extends Element>(parentElement: Element, ...selectors: string[]): T | null { | ||
const [selector, ...rest] = selectors; | ||
const elementList = parentElement.querySelectorAll(`[${attrName}~="${selector}"]`) as NodeListOf<T>; | ||
if(elementList.length === 0) { | ||
const elementList = parentElement.querySelectorAll(`[${attrName}~="${selector}"]`); | ||
if (elementList.length === 0) { | ||
return null; | ||
} else if(elementList.length === 1) { | ||
} else if (elementList.length === 1) { | ||
const element = elementList[0]; | ||
if(rest.length>0) { | ||
return select(element, ...rest); | ||
if (rest.length > 0) { | ||
return select<T>(element, ...rest); | ||
} else { | ||
return element; | ||
return element as T; | ||
} | ||
@@ -20,5 +20,5 @@ } else { | ||
return function (...selectors: string[]): T | null { | ||
return select(container, ...selectors); | ||
return function <T extends Element>(...selectors: string[]) { | ||
return select<T>(container, ...selectors); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
172
3222778