title: How to test function that requires user input in command line using mocha, chai, and robotjs?
body: <p>I am trying to unit test this function with mocha, chai, and robotjs. I am currently able to get robotjs to input data, but I am not able to test this function by itself. Right now my terminal is saying that I expected {} to equal 'https://toscrape.com/'. 'https://toscrape.com/' is the baseurl used in this function, and if the user types no, this should be returned. An object is returned from another function later down the line. How do I test this function?</p>
  <pre><code>// allow user to input a url and then validate url
  const requestSiteURL = async function () {
    let url = await new Promise((resolve) =&gt; {
      readline.question('Please type url: ', resolve);
    });
    let URL = 'https://toscrape.com/';
    if (validUrl.isUri(url)) {
      readline.close();
      return url;
    } else if (url.toLowerCase() === 'no') {
      url = URL;
      return url;
    } else {
      console.log(
        'Please type in a valid URL (https://toscrape.com/) or type &quot;no&quot; to use base url.'
      );
      return requestSiteURL();
    }
  };
  </code></pre>
  <p>here is my test case so far</p>
  <pre><code>
  const url = require('../crawler');
  const robot = require('robotjs');
  var chai = require('chai');
  var expect = chai.expect;
  
  var roboInput = () =&gt; {
    robot.typeString('no');
    robot.keyTap('enter');
  };
  
  describe('validates site url', function () {
    it('no', function () {
      roboInput();
      let result = url.requestSiteURL();
      expect(result).to.equal('https://toscrape.com/');
    });
  });
  </code></pre>