Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Angular, Fourth Edition

You're reading from   Learning Angular, Fourth Edition A no-nonsense guide to building web applications with Angular 15

Arrow left icon
Product type Paperback
Published in Feb 2023
Publisher Packt
ISBN-13 9781803240602
Length 446 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Pablo Deeleman Pablo Deeleman
Author Profile Icon Pablo Deeleman
Pablo Deeleman
Aristeidis Bampakos Aristeidis Bampakos
Author Profile Icon Aristeidis Bampakos
Aristeidis Bampakos
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Building Your First Angular Application FREE CHAPTER 2. Introduction to TypeScript 3. Organizing Application into Modules 4. Enabling User Experience with Components 5. Enrich Applications Using Pipes and Directives 6. Managing Complex Tasks with Services 7. Being Reactive Using Observables and RxJS 8. Communicating with Data Services over HTTP 9. Navigating through Application with Routing 10. Collecting User Data with Forms 11. Introduction to Angular Material 12. Unit Test an Angular Application 13. Bringing an Application to Production 14. Handling Errors and Application Debugging 15. Other Books You May Enjoy
16. 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 $19.99/month. Cancel anytime
Banner background image