title: How to mock and set function argument correctly in jest mock
body: <p>I would like to test my mocking by following <code>jest</code> script.I intended to mock <code>exec</code> in returnvalue<code>irohaResponse</code> but , when I run following test,<code>IrohaTransactionExec().exec(&quot;testArg1&quot;,&quot;testArg2&quot;)</code> was executed and not returned <code>irohaResponse</code></p>
  <p>What is the wrong point of that? and How can I mock correctly? Thanks</p>
  <pre><code>        it(&quot;mocking test&quot;,async ()=&gt;{
              const irohaResponse= registered;
              const iroha = new IrohaTransactionExec()
              const mockfunc = jest.spyOn(iroha,&quot;exec&quot;)
              mockfunc.mockReturnValue(Promise.resolve(irohaResponse))
              expect(await new IrohaTransactionExec().exec(&quot;testArg1&quot;,&quot;testArg2&quot;)).toEqual(irohaResponse)
          },10000)
  </code></pre>
  <pre><code>import { IrohaClientBuilder,IrohaRequestParam } from &quot;@post-pricing/library/lib/src/utility&quot;
  import { IrohaInterface } from &quot;@post-pricing/library/lib/src/const/irohaApi&quot;
  
  export class IrohaTransactionExec {
  
      private irohaClient:IrohaClientBuilder
      private irohaRequestParam:IrohaRequestParam
  
      constructor(){
          this.irohaRequestParam = new IrohaRequestParam()
      }
  
      public async exec (shopCode:string,nptransactionId:string):Promise&lt;IrohaInterface&gt; {
          this.irohaClient = new IrohaClientBuilder()
          const client = await this.irohaClient.buildIrohaClient()
          const result = await client.searchTransactionAsync(this.irohaRequestParam.get(shopCode,nptransactionId))
          return result[0].return
      } 
  
  }
  </code></pre>
  <pre><code> expect(received).toEqual(expected) // deep equality
  
      - Expected  - 37
      + Received  +  6
  
        Object {
          &quot;apiCommonResponseHeader&quot;: Object {
            &quot;attributes&quot;: Object {
              &quot;xsi:type&quot;: &quot;ax22:ApiCommonResponseHeader&quot;,
            },
      -     &quot;requestId&quot;: &quot;12345&quot;,
      -     &quot;resultStatus&quot;: 0,
      +     &quot;errorCodeList&quot;: Array [
      +       &quot;E0000007&quot;,
      +     ],
      +     &quot;requestId&quot;: &quot;PRC220909141357mwdix&quot;,
      +     &quot;resultStatus&quot;: 90,
            &quot;serviceType&quot;: &quot;01&quot;,
      -     &quot;shopCode&quot;: &quot;akt0000001&quot;,
      +     &quot;shopCode&quot;: &quot;testArg1&quot;}
  }
        20 |             const mockfunc = jest.spyOn(iroha,&quot;exec&quot;)
        21 |             mockfunc.mockReturnValue(Promise.resolve(irohaResponse))
      &gt; 22 |             expect(await new IrohaTransactionExec().exec(&quot;testArg1&quot;,&quot;testArg2&quot;)).toEqual(irohaResponse)
           |                                                                                  ^
        23 |         },10000)
       
  
        at Object.&lt;anonymous&gt; (test/functions/transactions/handler.spec.ts:22:82)
  
  ----------|---------|----------|---------|---------|-------------------
  File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
  ----------|---------|----------|---------|---------|-------------------
  All files |       0 |        0 |       0 |       0 |                   
  ----------|---------|----------|---------|---------|-------------------
  Test Suites: 1 failed, 1 total
  Tests:       1 failed, 1 total
  Snapshots:   0 total
  Time:        3.754 s, estimated 4 s
  </code></pre>