import { Browser } from 'mugshot';

/* istanbul ignore next because this will get stringified and sent to the browser */
function getBoundingRect(selector: string): DOMRect {
  // @ts-ignore because querySelector can be null and we don't
  // care about browsers that don't support it.
  return document.querySelector(selector).getBoundingClientRect();
}

/**
 * API adapter for WebdriverIO to make working with it saner.
 */
export default class WebdriverIOAdapter implements Browser {
  private browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser;

  constructor(browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser) {
    this.browser = browser;
  }

  takeScreenshot = async () => this.browser.takeScreenshot();

  getElementRect = async (selector: string) => {
    // @ts-ignore because the return type is not properly inferred
    const rect: DOMRect = await this.browser.execute(
      getBoundingRect,
      selector
    );

    return {
      x: rect.x,
      y: rect.y,
      width: rect.width,
      height: rect.height
    };
  };
}

import { Browser } from 'mugshot';

/**
 * API adapter for WebdriverIO to make working with it saner.
 */
export default class WebdriverIOAdapter implements Browser {
  private browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser;

  constructor(browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser) {
    this.browser = browser;
  }

  takeScreenshot = async () => this.browser.takeScreenshot();

  getElementRect = async (selector: string) => {
    // @ts-ignore because the return type is not properly inferred
    const rect: DOMRect = await this.browser.execute(
      WebdriverIOAdapter.getBoundingRect,
      selector
    );

    return {
      x: rect.x,
      y: rect.y,
      width: rect.width,
      height: rect.height
    };
  };

  private static getBoundingRect(selector: string): DOMRect {
    // @ts-ignore because querySelector can be null and we don't
    // care about browsers that don't support it.
    return document.querySelector(selector).getBoundingClientRect();
  }
}

--- 
+++ 
@@ -1,4 +1,11 @@
 import { Browser } from 'mugshot';
+
+/* istanbul ignore next because this will get stringified and sent to the browser */
+function getBoundingRect(selector: string): DOMRect {
+  // @ts-ignore because querySelector can be null and we don't
+  // care about browsers that don't support it.
+  return document.querySelector(selector).getBoundingClientRect();
+}
 
 /**
  * API adapter for WebdriverIO to make working with it saner.
@@ -15,7 +22,7 @@
   getElementRect = async (selector: string) => {
     // @ts-ignore because the return type is not properly inferred
     const rect: DOMRect = await this.browser.execute(
-      WebdriverIOAdapter.getBoundingRect,
+      getBoundingRect,
       selector
     );
 
@@ -26,10 +33,4 @@
       height: rect.height
     };
   };
-
-  private static getBoundingRect(selector: string): DOMRect {
-    // @ts-ignore because querySelector can be null and we don't
-    // care about browsers that don't support it.
-    return document.querySelector(selector).getBoundingClientRect();
-  }
 }
Fix stringified function breaking under istanbul
