title: Mocking asynchronous requests within react's getInitialState
body: <p>When i created this question, my doubt was about how would i be able to test an asynchronous request utilizing mocha/enzyme/chai/sinon.<br>
  I am sure that there are different ways, but a possible one is to mock it with a handmade function that returns the appropriate values (check the answer for details).<br>
  My getInitialState method is this:  </p>
  
  <pre><code>getInitialState: function() {
      var me = this;
      var documentData = null;
      var promise = me.getDocuments();
  
      promise.then(function(value) {
          var documents = value.map(function(obj) {
              return Object.keys(obj).sort().map(function(key) { 
                  return obj[key];
              });
          });
  
          documentData = documents;
      });
  
      return ({
          cd: false
      });
  },
  </code></pre>
  
  <p>And the getDocuments() function that returns a promise is this:   </p>
  
  <pre><code>getDocuments: function() {
      var deferred = when.defer();
  
      Collection.fetch({cd: workspaceInfo.getCD()}).then(
          function(results) {
              deferred.resolve(results);
          },
          deferred.reject
      );
  
      return deferred.promise;
  },
  </code></pre>
  
  <p>How can i successfuly test it? 
  Would i have to mock the getInitialState method itself? (is that even possible)<br>
  Or just the getDocuments function with some predictable return values?<br>
  Thanks in advance, any help will be appreciated.  </p>