title: How to unit test javascript ES6 classes that encapsulate their own creation within a static function?
body: <p>In Dan Schafer's React Europe talk (<a href="https://youtu.be/etax3aEe2dA?t=11m5s" rel="nofollow noreferrer">https://youtu.be/etax3aEe2dA?t=11m5s</a>), he showed <em>one approach</em> to handling authorization in a GraphQL server could be delegating to a business logic layer in which each business object class has a <a href="https://i.stack.imgur.com/HsdbM.png" rel="nofollow noreferrer">gen() function</a> that acts as the <em>"single source of truth"</em> for <strong>both fetching and authorization</strong>.</p>
  
  <p>He implies that these classes could have no public constructor, thereby making gen() the only way to instantiate one of these classes.</p>
  
  <p>As a C# dev, this wouldn't be [easily] unit-testable. Perhaps, I'm taking his example too literally.</p>
  
  <p>In ES2015, is it possible to unit test the business logic in isolation with this pattern? If so, can you provide an example please?</p>
  
  <hr>
  
  <p>Here's a related Q&amp;A, but it doesn't address my question exactly:</p>
  
  <p>Q: <a href="https://stackoverflow.com/q/38160489/6439734">With GraphQL, what is the benefit or necessity of declaring a backing model &quot;class&quot; that does not vary from the GraphQL &quot;Type&quot; in any obvious way?</a></p>
  
  <p>A: <a href="https://stackoverflow.com/a/38209996/6439734">https://stackoverflow.com/a/38209996/6439734</a></p>