From af635fa90e2428108dc7a49a500be2c259238719 Mon Sep 17 00:00:00 2001
From: Sammy Jelin <sjelin@gmail.com>
Date: Thu, 26 Jan 2017 11:46:10 -0800
Subject: [PATCH] chore(wdpromise): prefer `wdpromise.when` to
 `wdpromise.fulfilled` (#4018)

Closes https://github.com/angular/protractor/issues/3903
---
 lib/browser.ts  | 6 +++---
 lib/debugger.ts | 4 ++--
 lib/element.ts  | 4 ++--
 lib/runner.ts   | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/browser.ts b/lib/browser.ts
index eb5abba8a..620d8620a 100644
--- a/lib/browser.ts
+++ b/lib/browser.ts
@@ -694,7 +694,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
 
     let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
       if (this.plugins_.skipAngularStability() || this.bpClient) {
-        return wdpromise.fulfilled();
+        return wdpromise.when(null);
       } else {
         // Need to wrap this so that we read rootEl in the control flow, not synchronously.
         return this.angularAppRoot().then((rootEl: string) => {
@@ -755,7 +755,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
                       'return window.NG_PENDING_TIMEOUTS',
                       'Protractor.waitForAngular() - getting pending timeouts' + description);
                 } else {
-                  pendingTimeoutsPromise = wdpromise.fulfilled({});
+                  pendingTimeoutsPromise = wdpromise.when({});
                 }
                 let pendingHttpsPromise = this.executeScriptWithDescription(
                     clientSideScripts.getPendingHttpRequests,
@@ -1209,7 +1209,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
   pause(opt_debugPort?: number): wdpromise.Promise<any> {
     if (this.debugHelper.isAttached()) {
       logger.info('Encountered browser.pause(), but debugger already attached.');
-      return wdpromise.fulfilled(true);
+      return wdpromise.when(true);
     }
     let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js';
     let onStartFn = (firstTime: boolean) => {
diff --git a/lib/debugger.ts b/lib/debugger.ts
index 300af0b89..f62b86670 100644
--- a/lib/debugger.ts
+++ b/lib/debugger.ts
@@ -169,7 +169,7 @@ export class DebugHelper {
             res = 'Error while evaluating command: ' + e;
           }
           if (!wdpromise.isPromise(res)) {
-            res = wdpromise.fulfilled(res);
+            res = wdpromise.when(res);
           }
 
           return res.then((res: any) => {
@@ -237,7 +237,7 @@ export class DebugHelper {
    */
   private validatePortAvailability_(port: number): wdpromise.Promise<boolean> {
     if (this.debuggerValidated_) {
-      return wdpromise.fulfilled(false);
+      return wdpromise.when(false);
     }
 
     let doneDeferred = wdpromise.defer();
diff --git a/lib/element.ts b/lib/element.ts
index b60b004da..0d710701b 100644
--- a/lib/element.ts
+++ b/lib/element.ts
@@ -689,7 +689,7 @@ export class ElementArrayFinder extends WebdriverWebElement {
    *     value of the accumulator.
    */
   reduce(reduceFn: Function, initialValue: any): wdpromise.Promise<any> {
-    let valuePromise = wdpromise.fulfilled(initialValue);
+    let valuePromise = wdpromise.when(initialValue);
     return this.asElementFinders_().then((arr: ElementFinder[]) => {
       return arr.reduce((valuePromise: any, elementFinder: ElementFinder, index: number) => {
         return valuePromise.then((value: any) => {
@@ -863,7 +863,7 @@ export class ElementFinder extends WebdriverWebElement {
   static fromWebElement_(browser: ProtractorBrowser, webElem: WebElement, locator?: Locator):
       ElementFinder {
     let getWebElements = () => {
-      return wdpromise.fulfilled([webElem]);
+      return wdpromise.when([webElem]);
     };
     return new ElementArrayFinder(browser, getWebElements, locator).toElementFinder_();
   }
diff --git a/lib/runner.ts b/lib/runner.ts
index e79a197a7..0b17ebd08 100644
--- a/lib/runner.ts
+++ b/lib/runner.ts
@@ -258,7 +258,7 @@ export class Runner extends EventEmitter {
             });
 
     browser_.getProcessedConfig = () => {
-      return wdpromise.fulfilled(config);
+      return wdpromise.when(config);
     };
 
     browser_.forkNewDriverInstance = (opt_useSameUrl: boolean, opt_copyMockModules: boolean) => {