Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Angular - Fourth Edition

You're reading from  Learning Angular - Fourth Edition

Product type Book
Published in Feb 2023
Publisher Packt
ISBN-13 9781803240602
Pages 446 pages
Edition 4th Edition
Languages
Authors (2):
Aristeidis Bampakos Aristeidis Bampakos
Profile icon Aristeidis Bampakos
Pablo Deeleman Pablo Deeleman
Profile icon Pablo Deeleman
View More author details

Table of Contents (17) Chapters

Preface Building Your First Angular Application Introduction to TypeScript Organizing Application into Modules Enabling User Experience with Components Enrich Applications Using Pipes and Directives Managing Complex Tasks with Services Being Reactive Using Observables and RxJS Communicating with Data Services over HTTP Navigating through Application with Routing Collecting User Data with Forms Introduction to Angular Material Unit Test an Angular Application Bringing an Application to Production Handling Errors and Application Debugging Other Books You May Enjoy
Index

Testing pipes

As we learned in Chapter 5, Enrich Applications Using Pipes and Directives, a pipe is a TypeScript class that implements the PipeTransform interface. It exposes a transform method, which is usually synchronous, which means it is straightforward to test. The list.pipe.ts file contains a pipe that converts a comma-separated string into a list:

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
  name: 'list'
})
export class ListPipe implements PipeTransform {
  transform(value: string): string[] {
    return value.split(',');
  }
}

Writing a test for it is simple. The only thing that we need to do is to instantiate an instance of ListPipe and verify the outcome of the transform method with some mock data:

import { ListPipe } from './list.pipe';
describe('ListPipe', () => {
  it('create an instance', () => {
    const pipe = new ListPipe();
    expect(pipe).toBeTruthy...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}