本文整理汇总了TypeScript中@angular/compiler/testing.TestComponentBuilder.createAsync方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TestComponentBuilder.createAsync方法的具体用法?TypeScript TestComponentBuilder.createAsync怎么用?TypeScript TestComponentBuilder.createAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/compiler/testing.TestComponentBuilder
的用法示例。
在下文中一共展示了TestComponentBuilder.createAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp)
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
var position = 0;
var flipped = false;
var history = [
['/parent/child', 'root { parent { hello } }', '/super-parent/child'],
['/super-parent/child', 'root { super-parent { hello2 } }', '/parent/child'],
['/parent/child', 'root { parent { hello } }', false]
];
router.subscribe((_) => {
var location = fixture.debugElement.componentInstance.location;
var element = fixture.debugElement.nativeElement;
var path = location.path();
var entry = history[position];
expect(path).toEqual(entry[0]);
expect(element).toHaveText(entry[1]);
var nextUrl = entry[2];
if (nextUrl == false) {
flipped = true;
}
if (flipped && position == 0) {
async.done();
return;
}
position = position + (flipped ? -1 : 1);
if (flipped) {
location.back();
} else {
router.navigateByUrl(nextUrl);
}
});
router.navigateByUrl(history[0][0]);
});
}), 1000);
示例2: it
it('should correctly update the announce text', fakeAsyncTest(() => {
let appFixture: ComponentFixture<TestApp> = null;
builder.createAsync(TestApp).then(fixture => {
appFixture = fixture;
});
flushMicrotasks();
let buttonElement = appFixture.debugElement
.query(By.css('button')).nativeElement;
buttonElement.click();
// This flushes our 100ms timeout for the screenreaders.
tick(100);
expect(liveEl.textContent).toBe('Test');
}));
示例3: inject
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(TestComponent)
.then((rootTC: any) => {
rootTC.detectChanges();
// let homeInstance = rootTC.debugElement.children[0].componentInstance;
// let homeDOMEl = rootTC.debugElement.children[0].nativeElement;
// expect(getDOM().querySelectorAll(homeDOMEl, 'li').length).toEqual(0);
// homeInstance.newName = 'Minko';
// homeInstance.addName();
// rootTC.detectChanges();
// expect(getDOM().querySelectorAll(homeDOMEl, 'li').length).toEqual(1);
// expect(getDOM().querySelectorAll(homeDOMEl, 'li')[0].textContent).toEqual('Minko');
});
}));
示例4: it
it("should render User's status as card", inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(UserStatusCardComponent).then(componentFixture => {
const element = componentFixture.nativeElement;
componentFixture.componentInstance.user = new DoseAmigosUser();
componentFixture.componentInstance.user.id = 100;
componentFixture.componentInstance.user.name = "John Doe";
componentFixture.componentInstance.user.lastTimeDoseTaken = new Date();
componentFixture.componentInstance.user.nextTimeDoseScheduled = new Date();
componentFixture.detectChanges();
expect(
element.querySelectorAll("ion-card").length
).toBe(
1,
"should render User's status as card"
);
});
}));
示例5:
[TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TaskEdit).then(
(componentFixture: ComponentFixture<TaskEdit>) => {
const instance = componentFixture.debugElement.componentInstance;
componentFixture.detectChanges();
let controls = instance.taskEditForm.controls;
controls.owner.updateValue('b');
controls.description.updateValue('change task description');
componentFixture.detectChanges();
instance.onSubmit();
const task = mockTasksService.getById(_id);
chai.expect(task.owner).to.equal('b');
chai.expect(task.description).to.equal('change task description');
}
);
}
示例6: inject
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
tcb.createAsync(AppWithOutletListeners).then(fixture => {
let appInstance = fixture.debugElement.componentInstance;
let router = appInstance.router;
router.subscribe((_: any /** TODO #9100 */) => {
fixture.detectChanges();
expect(appInstance.helloCmp).toBeAnInstanceOf(HelloCmp);
expect(appInstance.helloCmp.message).toBe('Ahoy');
async.done();
});
// TODO(juliemr): This isn't necessary for the test to pass - figure
// out what's going on.
// router.navigateByUrl('/rainbow(pony)');
});
}));
示例7: inject
inject([TestComponentBuilder, DisqusService], (tcb: TestComponentBuilder, disqusService: DisqusService) => {
tcb.createAsync(DemoComponent)
.then((fixture: ComponentFixture<DemoComponent>) => {
let demoComponent: DemoComponent = fixture.componentInstance;
let compiled: any = fixture.debugElement.nativeElement;
spyOn(disqusService,'reset');
demoComponent.pageIdentifier = 'testId';
demoComponent.pageUrl = 'testUrl';
fixture.detectChanges();
compiled.querySelector('#btn-reset').click();
fixture.detectChanges();
expect(disqusService.reset).toHaveBeenCalledWith('testId','testUrl',true);
});
})
示例8: it
it('should have the submit button enabled after form changes', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TodoCmp).then((fixture) => {
fixture.detectChanges();
let instance = fixture.debugElement.componentInstance;
let compiled = fixture.debugElement.nativeElement;
instance.todoForm.controls.message.updateValue('abc');
fixture.detectChanges();
expect(compiled.getElementsByClassName('todo_button')[0].getAttribute('disabled')).toBe(null);
instance.todoForm.controls.message.updateValue(undefined);
fixture.detectChanges();
expect(compiled.getElementsByClassName('todo_button')[0].getAttribute('disabled')).not.toBe(null);
});
})));
示例9: it
() => {return tcb.createAsync(PPSStatusComponent).then(fixture => {
let component = fixture.componentInstance;
let nativeElement = fixture.nativeElement;
it('by hiding the message when it is empty', () => {
expect(component.message).toEqual('');
expect(nativeElement.querySelector('#msg')).toBe(null);
});
it('by showing the message when it is not null', () => {
let newValue = 'xiexie';
ms.AddMessage(newValue);
fixture.detectChanges();
expect(component.message).toEqual(newValue);
let el = nativeElement.querySelector('#msg');
expect(el).not.toBe(null);
expect(el.innerHTML).toContain(newValue);
});
})});
示例10: it
it('should initialize as paused displaying the default labels', done => {
testComponentBuilder
.createAsync(TimerWidgetComponent)
.then(componentFixture => {
componentFixture.componentInstance.ngOnInit();
componentFixture.detectChanges();
expect(componentFixture.componentInstance.buttonLabelKey)
.toEqual('start');
expect(componentFixture.nativeElement
.querySelector('button')
.innerHTML.trim())
.toEqual('Start Timer');
componentFixture.destroy();
done();
})
.catch(e => done.fail(e));
});