本文整理匯總了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));
});