Test-Drive the Pipe

The pipe class and its transform function is the easiest to test. Our pipe should transform a given list into a sorted list. Let’s list the tests we will need:

  • Should have the pipe’s name set to sort
  • Should sort tasks based on year
  • Should sort tasks based on year, then month
  • Should sort tasks based on year, month, then day
  • Should sort tasks based on year, month, day, then name

First, edit the files section in karma.conf.js to add a reference to the currently empty pipe file; place it before the reference to the service file, like so:

 './public/src/app/tasks/tasks-sort.pipe.js'​,
 './public/src/app/tasks/tasks.service.js'​,
 './public/src/app/tasks/tasks.component.js'​,

Restart Karma after saving the file. Then open the file ...

Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.