title: How to test object from factory with mocha with sinon
body: <h2>Background</h2>
  
  <p>I have a factory function that creates dogs that bark:</p>
  
  <pre><code>const dogFactory = () =&gt; {
      const bark = name =&gt; console.log(`${name} just barked!`);
  
      return{
          bark
      };
  }; 
  </code></pre>
  
  <p>One would use it like:</p>
  
  <pre><code>const dog = dogFactory();
  dog.bark("boby"); //"boby just barked!"
  </code></pre>
  
  <p>I also have an hotel of dogs. Business is not going good, so to keep appearances I am creating my own dogs ! This hotel thus takes a <code>dogFactory</code> as an argument and looks like the following:</p>
  
  <pre><code>const dogHotel = deps =&gt; {
      const {
          dogFactory
      } = deps;
  
      let dogsHosted = [];
  
      const feed = () =&gt; {
          dogsHosted.push(dogFactory());
          dogsHosted.forEach( (dog, i) =&gt; dog.bark(i));
      }
  
      return{
          feed
      };  
  };
  </code></pre>
  
  <p>You would use it like:</p>
  
  <pre><code>const hotelAwsome = dogHotel({dogFactory: dogFactory});
  hotelAwsome.feed();
  </code></pre>
  
  <p>This hotel feeds dogs. Because there is no business it creates a dog and then feeds everyone. Every time a dog is fed, it barks of happiness!</p>
  
  <h2>Problem</h2>
  
  <p>One would think that creating infinite dogs in a broken hotel would be the problem, but that is not the case!</p>
  
  <p>The problem here is that I want to make sure the dogs are happy barking. That is, that for each dog in the hotel <code>bark</code> is being called.</p>
  
  <h2>Code</h2>
  
  <p>This is currently my test. I am using <code>mocha</code> as a test suite, I am using <code>sinon</code> to spy on my fake factory objects:</p>
  
  <pre><code>const sinon = require( "sinon" );
  const chai = require( "chai" );
  const expect = chai.expect;
  
  describe("dog hotel", () =&gt; {
  
      const fakeFacory = () =&gt; {
          const bark = () =&gt; sinon.spy()
          return {bark};
      };
  
      it("should make the dogs bark with happiness when feeding them!", () =&gt; {
          const hotelAweomse = dogHotel({dogFactory: fakeFacory});
          hotelAwesome.feed();
          //expect something here 
      });
  });
  </code></pre>
  
  <p>The issue here is that I am passing a fake dog factory, but I can't check with sinon if the dog are barking or not!</p>
  
  <h2>Question</h2>
  
  <p>How do I test if the dogs that are created in the hotel, are barking?</p>