From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Testing pipes

Testing pipes - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Testing pipes

- Pipes are pure functions by design and they always return the same output for a given input. This makes them very easy to unit test when compared to services and components. I'm in a spec file for highlight text pipe. I used the Angular CLI tool to generate the pipe and Angular already populated the spec file with a simple test. Notice that there's no before each block here. That's because pipes are stateless and there's nothing we need to set up before testing the pipe. Let's add a few more tests to check for common use cases as well as a few edge cases. I'll start by making a new it block. I'll call this test wrap a simple string in a span but you can call your test whatever you'd like. In the callback for this test, I'll instantiate a new instance of the highlight text pipe. On the next line, I'll use Jasmine's expect function to actually run our pipe and generate an output to test against. I expect that when I call pipe.transform and pass in a value and a filter, I'll get a…

Contents