title: How to mock array data with object for unit testing in Angular 8
body: <p>I would like to write a unit test to test if the <code>expectedData</code> is showing as expected. The HTML code is working and it displays everything correctly.</p>
  <p>HTML code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="col-6 p-0 LHS" *ngIf="data &amp;&amp; data.type === 'App'"&gt;
    &lt;div *ngFor="let d of data"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-auto"&gt;Item1:&lt;/div&gt;
        &lt;div class="appItem1"&gt;{{d.item1}}&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>TS file:</p>
  <pre><code>  data = [{item1: &quot;Item 1&quot;, item2: &quot;Item 2&quot;}, type: &quot;App&quot;, display: true]; // sample input data
    expectedData;
  
    getExpectedData() {
      if (this.data &amp;&amp; this.data.item) {
        switch (this.data.type) {
          case (&quot;File&quot;):
             this.expectedData = $('.fileItem1')[0].innerHTML;  
            break;
          case (&quot;App&quot;):
            this.expectedData = $('.appItem1')[0].innerHTML;              
            break;
        }
      }
    }
  </code></pre>
  <p>My test case:</p>
  <pre><code>it('should verify expected data', () =&gt; {
      const mockdata= [{item1: &quot;Item 1&quot;}];
      mockdata.type= 'App'; // getting error because this can't be pushed to array
      mockdata.display= true; // getting error because this can't be pushed to array
      component.data = mockdata;
      fixture.detectChanges();
      component.getExpectedData();
      expect(component.expectedData).toBe(&quot;Item 1&quot;);
    });
  </code></pre>
  <p>However, in my test case, it doesn't seem to be working to mock the data to that type of data, are there any possible way to test the <code>getExpectedData()</code>?</p>
  <p>Thanks</p>