Isolated tests
It is often useful to test complex components without rendering them. To see how it can be done, let's write a test for the following component:
@Component({moduleId: module.id, templateUrl: 'compose.html'}) class ComposeCmp { form = new FormGroup({ title: new FormControl('', Validators.required), body: new FormControl('') }); constructor(private route: ActivatedRoute, private currentTime: CurrentTime, private actions: Actions) {} onSubmit() { const routerStateRoot = this.route.snapshot.root; const conversationRoute = routerStateRoot.firstChild; const conversationId = +conversationRoute.params['id']; const payload = Object.assign({}, this.form.value, {createdAt: this.currentTime()}); this.actions.next({ type: 'reply', conversationId: conversationId, payload: payload }); } }
Here's the compose.html
file:
<form...