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 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.