title: Angular 4/5 Render2 Jasmine testing
body: <p>I have an interface which intent to manipulate DOM elements based on the input argument object. I am trying to write unit test first. The idea is to use Render2 available in Angular. </p>
  
  <pre><code>export interface ModifyDomTree {
      modify(data: SomeData) : ElementRef;
  }
  </code></pre>
  
  <p>It's implementation (No idea how this will come up) but writing test's for it.</p>
  
  <pre><code>export class ModifyDomTreeImpl implements ModifyDomTree {
     constructor(private render: Renderer2) {
     }
     modify(data: SomeData) : ElementRef{
          return null;
     }
  }
  </code></pre>
  
  <p>In the test I don't want to use a mock for Renderer2 I want to use the actual Renderer2 which will be used by Angular. How do I inject or instantiate actual Angular Render2 in the test?</p>
  
  <p>The spec would be </p>
  
  <pre><code>describe('ModifyDomTreeImpl', () =&gt; {
  let data: SomeData;
  let modifyDomTree: ModifyDomTree;
  
  beforeEach(() =&gt; {
      //let render: Renderer2 = mock(Renderer2); ?? How Do I inject the real Angular thing here
      modifyDomTree = new ModifyDomTreeImpl(render);
  });
  
  it('should convert a data into a text node', () =&gt; {
     data = mock(SomeData);
     when(data.value).thenReturn('Groot!!');
     const result: ElementRef = modifyDomTree.convert(data);
     expect(result).toBeDefined();
     expect(result).not.toBeNull();
     expect(result.nativeElement).toBeDefined();
     expect(result.nativeElement).toBeDefined();
     expect(result.nativeElement.childNodes).toBeDefined();
     expect(result.nativeElement.childNodes.length).toEqual(1);
     expect(result.nativeElement.childNodes.length[0]).toEqual('text');
     expect(result.nativeElement.childNodes.length[0].data).toEqual('Groot!!');
    });
  });
  </code></pre>