【发布时间】:2016-10-20 16:42:27
【问题描述】:
这对我不起作用。请让下面的 Plunkr 工作。
describe("trying a test", () => {
beforeEach(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
TestBed.configureTestingModule({
declarations: [myCmp, ChildCmp]
});
});
it("test should work", () => {
const fixture = TestBed.createComponent(myCmp);
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");
});
});
【问题讨论】:
-
你特别坚持哪一点?
-
请阅读我的答案。
-
我需要有关此链接的帮助(也发布在答案中)-stackoverflow.com/questions/40178536/…
标签: unit-testing angular