Please make my Plunkr test pass - https://plnkr.co/edit/dH5UVuqQOhBrSbqjZekN?p=preview. The child component must be bound to the class property of tr, and this type of *ngFor is necessary too.
This is my parent component:
@Component({
selector: 'my-cmp',
template: `<div (click)="updateMe()"></div><tr class="child-cmp" *ngFor="let _testVar of _testVars" [_testVar]="_testVar">`
})
export class myCmp {
_testVars = ["initial value"];
private updateMe(): void {
this._testVars = ["updated value"];
}
}
I just want this test to work:
describe("trying a test", () => {
beforeEach(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
TestBed.configureTestingModule({
declarations: [myCmp, ChildCmp]
});
});
it("test should work", () => {
const fixture = TestBed.createComponent(myCmp);
fixture.detectChanges();
const div = fixture.debugElement.children[0];
const childCmp = div.queryAll(By.directive(ChildCmp));
const divEl = div.queryAll(By.css('div'));
divEl[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges();
expect(childCmp[0].nativeElement.textContent).toBe("updated value");
expect(true).toBe(true);
});
});