本文整理汇总了TypeScript中angular2/platform/common_dom.By类的典型用法代码示例。如果您正苦于以下问题:TypeScript By类的具体用法?TypeScript By怎么用?TypeScript By使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了By类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HomePage));
if (!cmpDebugElement) return;
userStatsDebugElement = cmpDebugElement.query(By.directive(UserStats));
micropostNewDebugElement = cmpDebugElement.query(By.directive(MicropostNew));
feedDebugElement = cmpDebugElement.query(By.directive(Feed));
});
示例2: expect
.then((testComponent) => {
testComponent.detectChanges();
let anchorElement =
testComponent.debugElement.query(By.css('a.detail-view')).nativeElement;
expect(DOM.getAttribute(anchorElement, 'href')).toEqual('detail');
async.done();
});
示例3: it
it('can show feed', () => {
const cmp:Feed = cmpDebugElement.componentInstance;
expect(cmp.feed.length).toEqual(2);
const el = cmpDebugElement.nativeElement;
expect(DOM.querySelectorAll(el, 'li .content').length).toEqual(2);
const avatarLink = DOM.querySelector(el, 'li>a');
expect(avatarLink.getAttribute('href')).toEqual('/users/1');
const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
expect(gravatarDebugElement.componentInstance.alt).toEqual('test user1');
const userLink = DOM.querySelector(el, '.user>a');
expect(userLink).toHaveText('test user1');
expect(userLink.getAttribute('href')).toEqual('/users/1');
const content = DOM.querySelector(el, '.content');
expect(content).toHaveText('content1');
const timestamp = DOM.querySelector(el, '.timestamp');
expect(timestamp.innerText).toMatch(/1 day ago/);
const deleteLinks = DOM.querySelectorAll(el, '.delete');
expect(deleteLinks[0]).toBeTruthy();
expect(deleteLinks[1]).toBeFalsy();
});
示例4: expect
tcb.createAsync(TestComponent).then((testComponent) => {
testComponent.detectChanges();
testComponent.debugElement.query(By.css('a.detail-view-self'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
示例5: getChildrenBySelector
/**
* Gets a child DebugElement by css selector.
*
* The child of DebugElement are other elements that are "known" to
* Angular.
*/
static getChildrenBySelector(parent: DebugElement, selector: string): DebugElement[] {
let results = [];
parent.queryAll(By.css(selector)).forEach((el) => results.push(el));
parent.children.forEach((de) => {
TestHelper.getChildrenBySelector(de, selector).forEach((el) => results.push(el));
});
return results;
}
示例6: it
it('can be shown', () => {
ctx.fixture.detectChanges();
expect(cmpDebugElement).toBeTruthy();
const cmp:UserList = cmpDebugElement.componentInstance;
expect(cmp.users.length).toEqual(2);
expect(DOM.querySelectorAll(cmpDebugElement.nativeElement, '.users>li').length).toEqual(2);
const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.alt).toEqual('test1');
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
const userLink:HTMLElement = cmpDebugElement.query(By.css('.users>li>a')).nativeElement;
expect(userLink.innerText).toEqual('test1');
expect(userLink.getAttribute('href')).toEqual('/users/1');
});
示例7: it
it('can follow', () => {
const cmp:FollowBtn = cmpDebugElement.componentInstance;
cmp.isFollowedByMe = false;
ctx.fixture.detectChanges();
const followBtn = cmpDebugElement.query(By.css('.follow-btn')).nativeElement;
expect(followBtn).toHaveText('Follow');
followBtn.click();
expect(cmp.isFollowedByMe).toBeTruthy();
expect(relationshipService.follow).toHaveBeenCalledWith('1');
});
示例8: spyOn
return tcb.createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
spyOn(fixture.componentInstance, "fileUploaded");
let el = fixture.debugElement.query(By.css('div#child'));
el.triggerEventHandler('drop', {
preventDefault(){
},
dataTransfer: {
files: [1, 2, 3],
items: [1, 2, 3]
}
});
window.setTimeout(()=> {
expect(fixture.componentInstance.fileUploaded).toHaveBeenCalledWith([1, 2, 3]);
}, 300);
});