Shallow testing

Testing component classes without rendering their templates works in certain scenarios, but not in all of them. Sometimes we can write a meaningful test only if we render a component's template. We can do that and still keep the test isolated. We just need to render the template without rendering the component's children. This is what is colloquially known as shallow testing. Let's see this approach in action in the following code:

@Component( {moduleId: module.id, templateUrl: 'conversations.html'}) export class ConversationsCmp { folder: Observable<string>; conversations: Observable<Conversation[]>; constructor(route: ActivatedRoute) { this.folder = route.params.pluck<string>('folder'); this.conversations = route.data.pluck<Conversation[]>('conversations'); ...

Get Angular Router now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.