title: sinon: How to stub an entire class, rather than just a method
body: <p>I have a class under test that creates instances of another class.  I want to stub out the entirety of the second class, so that its constructor never gets called.  For example, If I have this setup:</p>
  
  <p><strong>Test.js</strong></p>
  
  <pre><code>class Test {
    constructor() {
    }
  
    func() {
      let foo = new Foo()
      foo.hello()
    }
  }
  </code></pre>
  
  <p><strong>Foo.js</strong></p>
  
  <pre><code>class Foo {
    constructor() {
      this.a = 1
      this.b = 2
      this.c = 3
      console.log('original constructor')
    }
  
    hello() {
      console.log('original hello')
    }
  
    goodbye() {
      console.log('original goodbye')
    }
  }
  </code></pre>
  
  <p>In my test file, I want to somehow stub out the entirety of the <code>Foo</code> class, so that when I run my test for for <code>Test.func()</code> it doesn't call the original <code>Foo</code> constructor, but rather a stubbed constructor that returns an fake <code>Foo</code> object.  I'll then stub the <code>hello</code> function of the fake <code>Foo</code> object to print <code>stubbed hello</code> instead of <code>original hello</code>.</p>
  
  <p>How can I stub the entire class like this?</p>
  
  <p>NOTE: I do NOT want to create a stub instance that I can use inside my test file.  I need to stub the constructor itself, so that if something up the stack calls the constructor, it gets back a stub instance.</p>