title: How to mock a slice pipe in angular
body: <p><em>I am trying to write test cases for a component that uses a slice pipe. I checked several links telling how to mock a pipe for component unit testing. Here issue is that it is an inbuilt pipe so I don't know how tranform method will be.</em></p>
  <pre><code>         &lt;tr *ngFor=&quot;let item of filteredUsers  |slice: (page-1) * pageSize : page * pageSize | searchFilter:searchText
              &quot;&gt;
                  &lt;td&gt;&lt;input type=&quot;checkbox&quot; (change)=&quot;onChange(item.id, $event.target.checked)&quot;&gt;&lt;/td&gt;
                  &lt;td&gt;{{item.firstName}}&lt;/td&gt;
                  &lt;td&gt;{{item.surname}}&lt;/td&gt;
                  &lt;td&gt;{{item.phoneNumber}}&lt;/td&gt;
                  &lt;td&gt;{{item.email}}&lt;/td&gt;
                  &lt;td&gt;{{item.grossIncome}}&lt;/td&gt;
                  &lt;!-- &lt;td&gt;{{item.createdDate | date: 'dd/MM/yyyy' }} &lt;/td&gt; --&gt;
  
              &lt;/tr&gt;
  </code></pre>
  <p><strong>Code for spec</strong></p>
  <pre><code>  describe('fetchUserList()',()=&gt;{
      it('should get list of users from notification service',()=&gt;{
    // component.pageSize=10;
   
    component.pageOptions=[10,20,50,100];
    notificationServiceSpy.fetchUserList.and.returnValue(of({}))
    fixture.detectChanges();
    expect(component.userList.length).toBe(0);
    expect(component.userList).toEqual(component.filteredUsers);
    expect(component.userCountLogs.length).toBe(0);
    expect(notificationServiceSpy.fetchUserList).toHaveBeenCalled();
  })
  </code></pre>
  <p><strong>Here is the code for ngOnit hook</strong></p>
  <pre><code> ngOnInit() {
  this.pageOptions=[10,20,50,100];
  this.pageSize=this.pageOptions[0];
  this.userMappingForm = this.formBuilder.group({
    topicId: ['', Validators.required],
    users: this.formBuilder.array([])
  });
  
   this.fetchNotificationTopic();
   this.fetchUserList();
  }
  </code></pre>
  <p><strong>Here is the code for fetching user's list</strong></p>
  <pre><code>fetchUserList() {
  this.topicList = [];
  this.notificationService.fetchUserList(null).subscribe((data: any) =&gt; {
    if (data) {
       this.userList =this.filteredUsers= data;
  
      this.userCountLogs = data.length;
    }
  
  }, (err: HttpErrorResponse) =&gt; {
  
  });
  
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/FsDjH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FsDjH.png" alt="enter image description here" /></a></p>