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

Commit

Permalink
chore(types): fix transpile errors related to IThenable (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina authored Oct 25, 2016
1 parent cc45940 commit e6475ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
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 =
(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

0 comments on commit e6475ae

Please sign in to comment.