How do you mock typeorm's getManager using testdouble? : <p>When creating unit tests for <a href="https://github.com/typeorm/typeorm" rel="noreferrer">typeorm</a>, I want to mock my connection to the database so that I can run unit tests without actually ever connecting to the DB (a good thing!)</p>

<p>I see <a href="https://github.com/typeorm/typeorm/issues/171#issuecomment-347724850" rel="noreferrer">places</a> where people have mocked typeorm's repositories using <a href="https://github.com/testdouble/testdouble.js" rel="noreferrer">testdouble</a> (which I am also using), but I am trying to do this with <a href="https://github.com/typeorm/typeorm/blob/master/docs/working-with-entity-manager.md" rel="noreferrer">getManager</a> and am having an issue figuring out how to make it work.</p>

<p>Here's an example. I have a class that, in the constructor, creates an EntityManager by using getManager() for a connection called 'test':</p>

<pre><code>export class TestClass {
    constructor() {
        const test: EntityManager = getManager('test');
    }
}
</code></pre>

<p>Now I want to test that I can simply create this class. Here's a sample (using mocha, chai, and testdouble):</p>

<pre><code>describe('data transformer tests', () =&gt; {
    it('can create the test class', () =&gt; {

        // somehow mock getManager here

        const testClass: TestClass = new TestClass();
        chai.expect(testClass, 'could not create TestClass').to.not.be.null;
    });
});
</code></pre>

<p>When I try this, I get this error message from typeorm:</p>

<pre><code>ConnectionNotFoundError: Connection "test" was not found.
</code></pre>

<p>Here are some of the things I've tried to mock getManager:</p>

<pre><code>td.func(getManager)
</code></pre>

<p>same error as above.</p>

<pre><code>td.when(getManager).thenReturn(td.object('EntityMananger'));
</code></pre>

<p>gets the message:</p>

<pre><code>Error: testdouble.js - td.when - No test double invocation call detected for `when()`.
</code></pre>

<p>Any ideas what the magic sauce is here for mocking <code>getManager</code>?</p>
