我正在使用角度5.2.0。我有一个子组件
import { Component } from '@angular/core';
@Component({
template: `<div><\div>`
})
export class ChildComponent {
public childMethod() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
和一个父组件,该组件通过 ViewChild
import { Component, ViewChild } from '@angular/core';
import { ChildComponent } from 'child.component';
@Component({
template: `<child-component #child><\child-component>`
})
export class ParentComponent {
@ViewChild('child')
public child: ChildComponent;
public parentMethod() {
this.child.childMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
我要进行单元测试,以证明的调用parentMethod导致的调用childMethod。我有以下几点:
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ChildComponent } from './child.component';
import …Run Code Online (Sandbox Code Playgroud)