function setModeAndUrlParams(mode, opt_params) {
  const params = opt_params || {};
  stub.replace(
      util,
      'getCurrentUrl',
      () => {
        let currentUrl = 'https://www.example.com/';
        if (mode) {
          currentUrl += '?mode=' + encodeURIComponent(mode);
          for (let name in params) {
            currentUrl += `&${name}=` +
                encodeURIComponent(asserts.assertString(params[name]));
          }
        }
        return currentUrl;
      });
}
@param {string} mode The dispatcher mode to simulate.
@param {?Object=} opt_params The parameters in the URL to simulate.