title: Sinon JS Stubbing/Mocking undefined properties
body: <p>I am hoping someone will be able to help me out with a small issue. I am trying to stub out an undefined property that lives inside a function and return a known value, I am trying this with a simple test case:</p>
  
  <pre><code>var self = this;
  
  
  self.test = function() {
    return person.myId();
  };
  
  
  if (typeof module !== "undefined" &amp;&amp; module.hasOwnProperty("exports")) {
    module.exports = self;
  }
  
  
  return self;
  </code></pre>
  
  <p>what I have tried to do is:</p>
  
  <pre><code>it('Basic stub test', function() {
    sinon.stub(code, 'person.myId').return("1234");
    assert(code.test(), "1234");
  });
  </code></pre>
  
  <p>I had hoped the above would stub any calls made to person.myId(), however, I just get any error saying: Cannot stub non-existent own property person.myId.</p>
  
  <p>We use our own software that handles dependency injection (e.g. during runtime in our software person is made available) but we are attempting to write isolated unit tests outside of the software, hence the necessity for stubbing out the missing dependencies.</p>
  
  <p>Has anyone attempted this kind of thing before? Am I trying to do something that isn't possible?</p>
  
  <p>Thank you for any help/support anyone can provide.</p>
  
  <p>Sam </p>