title: How to test function argument inside an async function with Jest
body: <p>I have the following function</p>
  <pre class="lang-js prettyprint-override"><code>export const executeCommand = async (
    command: string
  ): Promise&lt;{ output: string; error: string }&gt; =&gt; {
    let output = &quot;&quot;;
    let error = &quot;&quot;;
  
    const options: exec.ExecOptions = {
      silent: true,
      listeners: {
        stdout: (data: Buffer) =&gt; {
          output += data.toString();
        },
        stderr: (data: Buffer) =&gt; {
          error += data.toString();
        },
      },
    };
    await exec.exec(command, null, options);
  
    return { output, error };
  };
  </code></pre>
  <p>I am trying to test the functionality of <code>stdout</code> and <code>stderr</code> but cannot. My current test looks like this</p>
  <pre class="lang-js prettyprint-override"><code>it(`should return the command output`, async () =&gt; {
    const stdOutBuffer: Buffer = new Buffer('The is some output');
    const {output} = await utils.executeCommand('');
    const stdOut = execMock.mock.calls[0][2].listeners.stdout;
    stdOut(stdOutBuffer);
    expect(output).toEqual('The is some output');
  });
  </code></pre>
  <p>The test fails with the below</p>
  <pre><code>    Expected: &quot;The is some output&quot;
      Received: &quot;&quot;
  </code></pre>
  <p>What am I doing wrong?</p>