inject([AsyncTestCompleter], (async) => {
   bootstrap(HierarchyAppCmp, [testBindings, bind(appBaseHrefToken).toValue('/my/app')])
       .then((applicationRef) => {
         var router = applicationRef.hostComponent.router;
         router.subscribe((_) => {
           expect(el).toHaveText('root { parent { hello } }');
           expect(applicationRef.hostComponent.location.path())
               .toEqual('/my/app/parent/child');
           async.done();
         });
         router.navigate('/parent/child');
       });
 }));
示例#2
0
function _getAppBindings() {
  var appDoc;
  try {
    appDoc = DOM.defaultDoc();
  } catch (e) {
    appDoc = null;
  }
  return [bind(appDocumentToken).toValue(appDoc), bind(ShadowDomStrategy).toFactory((styleUrlResolver, doc) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, doc.head), [StyleUrlResolver, appDocumentToken]), Compiler, CompilerCache, bind(TemplateResolver).toClass(MockTemplateResolver), bind(ChangeDetection).toValue(dynamicChangeDetection), TemplateLoader, DirectiveMetadataReader, Parser, Lexer, ExceptionHandler, bind(XHR).toClass(MockXHR), ComponentUrlMapper, UrlResolver, StyleUrlResolver, StyleInliner, TestBed, bind(VmTurnZone).toClass(MockVmTurnZone), bind(EventManager).toFactory((zone) => {
    var plugins = [new DomEventsPlugin()];
    return new EventManager(plugins, zone);
  }, [VmTurnZone])];
}
 static bindTo(childTokens): List<Binding> {
   return [
     bind(_CHILDREN)
         .toAsyncFactory((injector) => PromiseWrapper.all(
                             ListWrapper.map(childTokens, (token) => injector.asyncGet(token))),
                         [Injector]),
     bind(WebDriverExtension)
         .toFactory(
             (children, capabilities) => {
               var delegate;
               ListWrapper.forEach(children, (extension) => {
                 if (extension.supports(capabilities)) {
                   delegate = extension;
                 }
               });
               if (isBlank(delegate)) {
                 throw new BaseException('Could not find a delegate for given capabilities!');
               }
               return delegate;
             },
             [_CHILDREN, Options.CAPABILITIES])
   ];
 }
示例#4
0
 beforeEach(() => {
   injector = Injector.resolveAndCreate([
     BaseRequestOptions,
     MockBackend,
     bind(Http).toFactory(
         function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
           return new Http(backend, defaultOptions);
         },
         [MockBackend, BaseRequestOptions])
   ]);
   http = injector.get(Http);
   backend = injector.get(MockBackend);
   baseResponse = new Response(new ResponseOptions({body: 'base response'}));
 });
示例#5
0
 jsmFn(name, function(done) {
   var async = false;
   var completerBinding = bind(AsyncTestCompleter).toFactory(() => {
     if (!inIt)
       throw new Error('AsyncTestCompleter can only be injected in an "it()"');
     async = true;
     return new AsyncTestCompleter(done);
   });
   var injector = createTestInjector([...testBindings, completerBinding]);
   runner.run(injector);
   if (!(fn instanceof FunctionWithParamTokens)) {
     fn = inject([], fn);
   }
   inIt = true;
   fn.execute(injector);
   inIt = false;
   if (!async)
     done();
 });
示例#6
0
/**
 * Returns the application injector bindings.
 *
 * This must be kept in sync with _injectorBindings() in application.js
 *
 * @returns {any[]}
 */
function _getAppBindings() {
  var appDoc;

  // The document is only available in browser environment
  try {
    appDoc = DOM.defaultDoc();
  } catch (e) {
    appDoc = null;
  }
  return [
    bind(DOCUMENT_TOKEN)
        .toValue(appDoc),
    bind(ShadowDomStrategy)
        .toFactory((styleUrlResolver, doc) =>
                           new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, doc.head),
                   [StyleUrlResolver, DOCUMENT_TOKEN]),
    DomRenderer,
    DefaultDomCompiler,
    bind(Renderer).toAlias(DomRenderer),
    bind(RenderCompiler).toAlias(DefaultDomCompiler),
    ProtoViewFactory,
    AppViewPool,
    AppViewManager,
    AppViewManagerUtils,
    ELEMENT_PROBE_CONFIG,
    bind(APP_VIEW_POOL_CAPACITY).toValue(500),
    Compiler,
    CompilerCache,
    bind(TemplateResolver).toClass(MockTemplateResolver),
    bind(PipeRegistry).toValue(defaultPipeRegistry),
    bind(ChangeDetection).toClass(DynamicChangeDetection),
    TemplateLoader,
    DynamicComponentLoader,
    DirectiveResolver,
    Parser,
    Lexer,
    ExceptionHandler,
    bind(XHR).toClass(MockXHR),
    ComponentUrlMapper,
    UrlResolver,
    StyleUrlResolver,
    StyleInliner,
    TestBed,
    TestComponentBuilder,
    bind(NgZone).toClass(MockNgZone),
    bind(EventManager)
        .toFactory(
            (zone) => {
              var plugins = [
                new DomEventsPlugin(),
              ];
              return new EventManager(plugins, zone);
            },
            [NgZone]),
  ];
}
示例#7
0
文件: http.ts 项目: synaptek/angular
 * #Example
 *
 * ```
 * import {HTTP_BINDINGS, Http} from 'http/http';
 * @Component({selector: 'http-app', viewBindings: [HTTP_BINDINGS]})
 * @View({template: '{{data}}'})
 * class MyApp {
 *   constructor(http:Http) {
 *     http.request('data.txt').subscribe(res => this.data = res.text());
 *   }
 * }
 * ```
 *
 */
export const HTTP_BINDINGS: List<any> = [
  bind(ConnectionBackend)
      .toClass(XHRBackend),
  BrowserXhr,
  bind(RequestOptions).toClass(BaseRequestOptions),
  bind(ResponseOptions).toClass(BaseResponseOptions),
  Http
];

export const JSONP_BINDINGS: List<any> = [
  bind(ConnectionBackend)
      .toClass(JSONPBackend),
  BrowserJsonp,
  bind(RequestOptions).toClass(BaseRequestOptions),
  bind(ResponseOptions).toClass(BaseResponseOptions),
  Jsonp
];
import {
  ShadowDomStrategy,
  NativeShadowDomStrategy,
  EmulatedScopedShadowDomStrategy,
  EmulatedUnscopedShadowDomStrategy
} from 'angular2/render';
import {bind} from 'angular2/di';
import {document} from 'angular2/src/facade/browser';
import {DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';

export function hasNativeShadowDom() {
  return Boolean(document && document.body && document.body.createShadowRoot);
}

export var emulatedScopedShadowDomInjectables = [
  bind(ShadowDomStrategy).toFactory((doc) => {
    return new EmulatedScopedShadowDomStrategy(doc.body);
  }, [DOCUMENT_TOKEN])
];

// use EmulatedScope if Native is not supported
export var nativeShadowDomInjectables = hasNativeShadowDom() ? [
    bind(ShadowDomStrategy).toClass(NativeShadowDomStrategy)
  ] : emulatedScopedShadowDomInjectables;

export var emulatedUnscopedShadowDomInjectables = [
  bind(ShadowDomStrategy).toFactory((doc) => {
    return new EmulatedUnscopedShadowDomStrategy(doc.body);
  }, [DOCUMENT_TOKEN])
];
示例#9
0
import {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils';
import {AppViewListener} from 'angular2/src/core/compiler/view_listener';
import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
import {Renderer, RenderCompiler} from 'angular2/src/render/api';
import {DomRenderer, DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';
import {DefaultDomCompiler} from 'angular2/src/render/dom/compiler/compiler';
import {internalView} from 'angular2/src/core/compiler/view_ref';

import {appComponentRefToken, appComponentTypeToken} from './application_tokens';

var _rootInjector: Injector;

// Contains everything that is safe to share between applications.
var _rootBindings = [bind(Reflector).toValue(reflector), TestabilityRegistry];

function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
  var bestChangeDetection: Type = DynamicChangeDetection;
  if (PreGeneratedChangeDetection.isSupported()) {
    bestChangeDetection = PreGeneratedChangeDetection;
  } else if (JitChangeDetection.isSupported()) {
    bestChangeDetection = JitChangeDetection;
  }
  return [
    bind(DOCUMENT_TOKEN)
        .toValue(DOM.defaultDoc()),
    bind(appComponentTypeToken).toValue(appComponentType),
    bind(appComponentRefToken)
        .toFactory(
            (dynamicComponentLoader, injector, testability, registry) => {
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../custom_typings/ng2.d.ts" />
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/core';
import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver';
import {bind} from 'angular2/di';
import {document} from 'angular2/src/facade/browser';

export var hasShadowDom = Boolean(document && document.body && document.body.createShadowRoot);

export var shadowDomInjectables = [
  (!hasShadowDom) ? [] :
  bind(ShadowDomStrategy).toFactory(
    styleUrlResolver => new NativeShadowDomStrategy(styleUrlResolver),
    [StyleUrlResolver]
  )
]