Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

chore(types): fix transpile errors related to IThenable #3650

Merged
merged 2 commits into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ export class ProtractorBrowser extends Webdriver {
clientSideScripts.testForAngular, msg('test for angular'),
Math.floor(timeout / 1000), this.ng12Hybrid)
.then(
(angularTestResult: {ver: string, message: string}) => {
(angularTestResult: {ver: number, message: string}) => {
let angularVersion = angularTestResult.ver;
if (!angularVersion) {
let message = angularTestResult.message;
Expand Down
4 changes: 3 additions & 1 deletion lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* it down, and setting up the driver correctly.
*/
import * as q from 'q';

import {Config} from '../config';

let webdriver = require('selenium-webdriver');

export class DriverProvider {
Expand Down Expand Up @@ -61,7 +63,7 @@ export class DriverProvider {
if (driver.getSession() === undefined) {
deferred.resolve();
} else {
driver.getSession().then((session_: string) => {
driver.getSession().then((session_) => {
if (session_) {
driver.quit().then(function() {
deferred.resolve();
Expand Down
67 changes: 32 additions & 35 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,32 +178,25 @@ export class ElementArrayFinder extends WebdriverWebElement {
}
});
} else {
return this.getWebElements().then(
(parentWebElements: webdriver.WebElement[]) => {
// For each parent web element, find their children and construct
// a
// list of Promise<List<child_web_element>>
let childrenPromiseList = parentWebElements.map(
(parentWebElement: webdriver.WebElement) => {
return locator.findElementsOverride ?
locator.findElementsOverride(
ptor.driver, parentWebElement, ptor.rootEl) :
parentWebElement.findElements(locator);
});
return this.getWebElements().then((parentWebElements: WebElement[]) => {
// For each parent web element, find their children and construct
// a list of Promise<List<child_web_element>>
let childrenPromiseList = parentWebElements.map(
(parentWebElement: webdriver.WebElement) => {
return locator.findElementsOverride ?
locator.findElementsOverride(
ptor.driver, parentWebElement, ptor.rootEl) :
parentWebElement.findElements(locator);
});

// Resolve the list of Promise<List<child_web_elements>> and merge
// into
// a single list
return wdpromise.all(childrenPromiseList)
.then((resolved: webdriver.WebElement[]) => {
return resolved.reduce(
(childrenList: webdriver.WebElement[],
resolvedE: webdriver.WebElement) => {
return childrenList.concat(resolvedE);
},
[]);
});
});
// Resolve the list of Promise<List<child_web_elements>> and merge
// into a single list
return wdpromise.all(childrenPromiseList).then((resolved) => {
return resolved.reduce((childrenList, resolvedE) => {
return childrenList.concat(resolvedE);
}, []);
});
});
}
};
return new ElementArrayFinder(this.browser_, getWebElements, locator);
Expand Down Expand Up @@ -501,7 +494,9 @@ export class ElementArrayFinder extends WebdriverWebElement {
* @returns {!webdriver.promise.Promise} A promise which will resolve to
* an array of ElementFinders represented by the ElementArrayFinder.
*/
then(fn?: Function, errorFn?: Function): wdpromise.Promise<any[]> {
then(
fn?: (value: any) => {} | wdpromise.IThenable<{}>,
errorFn?: (error: any) => any): wdpromise.Promise<any[]> {
if (this.actionResults_) {
return this.actionResults_.then(fn, errorFn);
} else {
Expand Down Expand Up @@ -726,7 +721,7 @@ export class ElementArrayFinder extends WebdriverWebElement {
export class ElementFinder extends WebdriverWebElement {
parentElementArrayFinder: ElementArrayFinder;
elementArrayFinder_: ElementArrayFinder;
then: (fn: Function, errorFn: Function) => wdpromise.Promise<any> = null;
then: (fn: Function, errorFn?: Function) => wdpromise.Promise<any> = null;

constructor(
public browser_: ProtractorBrowser,
Expand All @@ -751,14 +746,16 @@ export class ElementFinder extends WebdriverWebElement {
* of
* evaluating fn.
*/
this.then = (fn: Function, errorFn: Function) => {
return this.elementArrayFinder_.then((actionResults: any) => {
if (!fn) {
return actionResults[0];
}
return fn(actionResults[0]);
}, errorFn);
};
this.then =
Copy link
Contributor

@thorn0 thorn0 Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be made generic as well as the other then functions above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @juliemr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good case for generics, because we don't actually know what value it will return based on the arguments to the function - it's based on what has been called in the chain.

(fn: (value: any) => {} | wdpromise.IThenable<{}>,
errorFn?: (error: any) => any) => {
return this.elementArrayFinder_.then((actionResults: any) => {
if (!fn) {
return actionResults[0];
}
return fn(actionResults[0]);
}, errorFn);
};
}

// This filter verifies that there is only 1 element returned by the
Expand Down
3 changes: 2 additions & 1 deletion lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export class ProtractorExpectedConditions {
Function {
var hasText = () => {
return elementFinder.getText().then((actualText: string): boolean => {
// MSEdge does not properly remove newlines, which causes false negatives
// MSEdge does not properly remove newlines, which causes false
// negatives
return actualText.replace(/\r?\n|\r/g, '').indexOf(text) > -1;
});
};
Expand Down