本文整理汇总了TypeScript中angular2/src/platform/dom/dom_adapter.DOM类的典型用法代码示例。如果您正苦于以下问题:TypeScript DOM类的具体用法?TypeScript DOM怎么用?TypeScript DOM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOM类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should return the value of the base element', () => {
var baseEl = DOM.createElement('base');
DOM.setAttribute(baseEl, 'href', '/drop/bass/connon/');
var headEl = DOM.defaultDoc().head;
DOM.appendChild(headEl, baseEl);
var baseHref = DOM.getBaseHref();
DOM.removeChild(headEl, baseEl);
DOM.resetBaseElement();
expect(baseHref).toEqual('/drop/bass/connon/');
});
示例2: it
it('should return a relative url', () => {
var baseEl = DOM.createElement('base');
DOM.setAttribute(baseEl, 'href', 'base');
var headEl = DOM.defaultDoc().head;
DOM.appendChild(headEl, baseEl);
var baseHref = DOM.getBaseHref();
DOM.removeChild(headEl, baseEl);
DOM.resetBaseElement();
expect(baseHref.endsWith('/base')).toBe(true);
});
示例3: it
it('deletes micropost when confirmed', done => {
const cmp:Feed = cmpDebugElement.componentInstance;
const testCmp:TestCmp = ctx.fixture.debugElement.componentInstance;
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(true);
spyOn(cmp, 'list');
spyOn(testCmp, 'listenDeleted');
ObservableWrapper.subscribe(cmp.deleted, () => {
expect(cmp.list).toHaveBeenCalled();
expect(testCmp.listenDeleted).toHaveBeenCalled();
done();
});
deleteLink.click();
});
示例4: main
export function main() {
var typedComponentFactory = typed.CompANgFactory;
var untypedComponentFactory = untyped.CompANgFactory;
var fixtures: TestFixture[] = [];
if (IS_DART || !DOM.supportsDOMEvents()) {
// Our generator only works on node.js and Dart...
fixtures.push(new TestFixture(typedComponentFactory, 'typed'));
}
if (!IS_DART) {
// Our generator only works on node.js and Dart...
if (!DOM.supportsDOMEvents()) {
fixtures.push(new TestFixture(untypedComponentFactory, 'untyped'));
}
}
describe('OfflineCompiler', () => {
var injector: Injector;
var sharedStylesHost: SharedStylesHost;
beforeEach(inject([Injector, SharedStylesHost], (_injector, _sharedStylesHost) => {
injector = _injector;
sharedStylesHost = _sharedStylesHost;
}));
fixtures.forEach((fixture) => {
describe(`${fixture.name}`, () => {
it('should compile components', () => {
var hostEl = fixture.compFactory.create(injector);
expect(hostEl.instance).toBeAnInstanceOf(CompA);
var styles = sharedStylesHost.getAllStyles();
expect(styles[0]).toContain('.redStyle[_ngcontent');
expect(styles[1]).toContain('.greenStyle[_ngcontent');
});
});
});
});
}
示例5: it
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
const cmp:UserStats = cmpDebugElement.componentInstance;
expect(cmp.userId).toEqual('1');
expect(cmp.user).toBeTruthy();
expect(cmp.user.id).toEqual(1);
expect(cmp.user.email).toEqual('test1@test.com');
expect(cmp.user.userStats.micropostCnt).toEqual(2);
const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
expect(gravatarDebugElement.componentInstance.alt).toEqual('test1');
const el = cmpDebugElement.nativeElement;
const header = DOM.querySelector(el, 'h2');
expect(header.innerText).toMatch(/test1/);
const profileLink = DOM.querySelector(el, 'a.profile-link');
expect(profileLink).toBeTruthy();
expect(profileLink.getAttribute('href')).toEqual('/users/1');
const postCnt = DOM.querySelector(el, '.microposts');
expect(postCnt).toBeTruthy();
expect(postCnt.innerText).toMatch(/2 microposts/);
const followingsLink = DOM.querySelector(el, 'a.followings');
expect(followingsLink).toBeTruthy();
expect(followingsLink.getAttribute('href')).toEqual('/users/1/followings');
expect(followingsLink.innerText).toMatch(/3[\s\S]*?followings/);
const followersLink = DOM.querySelector(el, 'a.followers');
expect(followersLink).toBeTruthy();
expect(followersLink.getAttribute('href')).toEqual('/users/1/followers');
expect(followersLink.innerText).toMatch(/4[\s\S]*?followers/);
});
示例6: setup
return setup(template).then((fixture: ComponentFixture) => {
let element: DebugElement = fixture.debugElement.query(By.css('[md-ink]'));
let save = Ink.rippleEvent;
let fired = false;
Ink.rippleEvent = () => {
fired = true;
return Promise.resolve();
};
let event = DOM.createEvent('mouse');
element.triggerEventHandler('mousedown', event);
expect(fired).toBe(false);
Ink.rippleEvent = save;
});
示例7:
.then(rootTC => {
rootTC.detectChanges();
let appDOMEl = rootTC.debugElement.children[0].nativeElement;
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option').length).toBe(5);
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option')[0].value).toBe('en');
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option')[1].value).toBe('es');
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option')[2].value).toBe('fr');
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option')[3].value).toBe('ru');
t.e(DOM.querySelectorAll(appDOMEl, 'form > select option')[4].value).toBe('bg');
});
示例8: _injectorProviders
// TODO: This code is nearly identical to core/application. There should be a way to only write it
// once
function _injectorProviders(): any[] {
return [
provide(DOCUMENT, {useValue: DOM.defaultDoc()}),
EventManager,
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}),
new Provider(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}),
new Provider(EVENT_MANAGER_PLUGINS, {useClass: HammerGesturesPlugin, multi: true}),
provide(DomRenderer, {useClass: DomRenderer_}),
provide(Renderer, {useExisting: DomRenderer}),
APP_ID_RANDOM_PROVIDER,
DomSharedStylesHost,
provide(SharedStylesHost, {useExisting: DomSharedStylesHost}),
Serializer,
provide(ON_WEB_WORKER, {useValue: false}),
provide(ElementSchemaRegistry, {useValue: new DomElementSchemaRegistry()}),
RenderViewWithFragmentsStore,
RenderProtoViewRefStore,
AppViewPool,
provide(APP_VIEW_POOL_CAPACITY, {useValue: 10000}),
provide(AppViewManager, {useClass: AppViewManager_}),
AppViewManagerUtils,
AppViewListener,
ProtoViewFactory,
ViewResolver,
provide(PLATFORM_PIPES, {useValue: COMMON_PIPES, multi: true}),
provide(PLATFORM_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
DirectiveResolver,
Parser,
Lexer,
provide(ExceptionHandler, {useFactory: () => new ExceptionHandler(DOM), deps: []}),
provide(XHR, {useValue: new XHRImpl()}),
UrlResolver,
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
Testability,
AnchorBasedAppRootUrl,
provide(AppRootUrl, {useExisting: AnchorBasedAppRootUrl}),
WebWorkerApplication,
WebWorkerSetup,
MessageBasedXHRImpl,
MessageBasedRenderer,
provide(ServiceMessageBrokerFactory, {useClass: ServiceMessageBrokerFactory_}),
provide(ClientMessageBrokerFactory, {useClass: ClientMessageBrokerFactory_}),
BrowserDetails,
AnimationBuilder
];
}
示例9: it
it('should support duration and delay', inject([AnimationBuilder], (animate) => {
var animateCss = animate.css();
animateCss.setDelay(100).setDuration(200);
expect(animateCss.data.duration).toBe(200);
expect(animateCss.data.delay).toBe(100);
var element = el('<div></div>');
var runner = animateCss.start(element);
runner.flush();
if (DOM.supportsAnimation()) {
expect(runner.computedDelay).toBe(100);
expect(runner.computedDuration).toBe(200);
} else {
expect(runner.computedDelay).toBe(0);
expect(runner.computedDuration).toBe(0);
}
}));
示例10: 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');
});