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'); } }
This constructor, although short, may look a bit funky if you are not familiar with RxJS. So let's step through it....