title: how to mock a module that takes a parameter
body: <p>I am trying to write a unit test for code that uses pg-promise, it looks like this:</p>
  
  <pre><code>const pgp = require('pg-promise')();
  
  const cn = {
    host: process.env.DB_HOST,
    port: 5432,
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD
  };
  
  function insertStuff(stuff) {
    let db = pgp(cn);
    return db.one('INSERT INTO test(stuff) VALUES ($1) RETURNING id, stuff', [stuff])
      .then(data =&gt; {
        return data
      })
   }
   module.exports.insertStuff = insertStuff
  </code></pre>
  
  <p>The test code looks like this:</p>
  
  <pre><code>const mockFakeDb = {
    one: jest.fn()
  }
  
  jest.mock("pg-promise", () =&gt; {
    return mockFakeDb
  })
  
   const insertStuff = require("../src/db-utils").insertStuff
  
   test("params for inserting stuff are correct", done =&gt; {
     mockFakeDb.one.mockImplementationOnce(() =&gt; {
      return Promise.resolve({id: 123456789, stuff: "stuff"})
  
     insertStuff("stuff").then((data) =&gt; {
     const insertCall = fakeDb.one.mock.calls[0]
     expect(insertCall).toHaveBeenCalledTimes(1)
     done()
   })
  })
  </code></pre>
  
  <p>so in trying to mock pg-promise require I get an error:<br>
  TypeError: require(...) is not a function.<br>
  I can see that pg-promise has a function which takes parameters (the second brackets) but not sure how to now mock this?</p>