当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript DOM.supportsDOMEvents方法代码示例

本文整理汇总了TypeScript中angular2/src/platform/dom/dom_adapter.DOM.supportsDOMEvents方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DOM.supportsDOMEvents方法的具体用法?TypeScript DOM.supportsDOMEvents怎么用?TypeScript DOM.supportsDOMEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular2/src/platform/dom/dom_adapter.DOM的用法示例。


在下文中一共展示了DOM.supportsDOMEvents方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: main

export function main() {
  if (!DOM.supportsDOMEvents()) return;
  describe('upgrade metadata', () => {
    it('should extract component selector', () => {
      expect(getComponentInfo(ElementNameComponent).selector).toEqual('elementNameDashed');
    });


    describe('errors', () => {
      it('should throw on missing selector', () => {
        expect(() => getComponentInfo(AttributeNameComponent))
            .toThrowErrorWith(
                "Only selectors matching element names are supported, got: [attr-name]");
      });

      it('should throw on non element names', () => {
        expect(() => getComponentInfo(NoAnnotationComponent))
            .toThrowErrorWith("No Directive annotation found on NoAnnotationComponent");
      });
    });

    describe('parseFields', () => {
      it('should process nulls', () => { expect(parseFields(null)).toEqual([]); });

      it('should process values', () => {
        expect(parseFields([' name ', ' prop :  attr ']))
            .toEqual([
              {
                prop: 'name',
                attr: 'name',
                bracketAttr: '[name]',
                parenAttr: '(name)',
                bracketParenAttr: '[(name)]',
                onAttr: 'onName',
                bindAttr: 'bindName',
                bindonAttr: 'bindonName'
              },
              {
                prop: 'prop',
                attr: 'attr',
                bracketAttr: '[attr]',
                parenAttr: '(attr)',
                bracketParenAttr: '[(attr)]',
                onAttr: 'onAttr',
                bindAttr: 'bindAttr',
                bindonAttr: 'bindonAttr'
              }
            ]);
      });
    })
  });
}
开发者ID:bet4vlom,项目名称:angular,代码行数:52,代码来源:metadata_spec.ts

示例2: 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');
        });
      });
    });
  });
}
开发者ID:JavaScript-Resource,项目名称:angular,代码行数:37,代码来源:offline_compiler_spec.ts

示例3: describe


//.........这里部分代码省略.........

    it('should update nested routes when url changes',
       fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
         let fixture = tcb.createFakeAsync(RootCmp);

         router.navigateByUrl('/team/22/user/victor');
         advance(fixture);
         let team1 = fixture.debugElement.children[1].componentInstance;

         router.navigateByUrl('/team/22/user/fedor');
         advance(fixture);
         let team2 = fixture.debugElement.children[1].componentInstance;

         expect(team1).toBe(team2);
         expect(fixture.debugElement.nativeElement).toHaveText('team 22 { hello fedor, aux:  }');
       })));

    it('should not unload the route if can deactivate returns false',
       fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
         let fixture = tcb.createFakeAsync(RootCmp);

         router.navigateByUrl('/team/22/cannotDeactivate');
         advance(fixture);

         router.navigateByUrl('/team/22/user/fedor');
         advance(fixture);

         expect(fixture.debugElement.nativeElement)
             .toHaveText('team 22 { cannotDeactivate, aux:  }');

         expect(location.path()).toEqual('/team/22/cannotDeactivate');
       })));

    if (DOM.supportsDOMEvents()) {
      it("should support absolute router links",
         fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
           let fixture = tcb.createFakeAsync(RootCmp);
           advance(fixture);

           router.navigateByUrl('/team/22/link');
           advance(fixture);
           expect(fixture.debugElement.nativeElement).toHaveText('team 22 { link, aux:  }');

           let native = DOM.querySelector(fixture.debugElement.nativeElement, "a");
           expect(DOM.getAttribute(native, "href")).toEqual("/team/33/simple");
           DOM.dispatchEvent(native, DOM.createMouseEvent('click'));
           advance(fixture);

           expect(fixture.debugElement.nativeElement).toHaveText('team 33 { simple, aux:  }');
         })));

      it("should support relative router links",
         fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
           let fixture = tcb.createFakeAsync(RootCmp);
           advance(fixture);

           router.navigateByUrl('/team/22/relativelink');
           advance(fixture);
           expect(fixture.debugElement.nativeElement)
               .toHaveText('team 22 { relativelink {  }, aux:  }');

           let native = DOM.querySelector(fixture.debugElement.nativeElement, "a");
           expect(DOM.getAttribute(native, "href")).toEqual("/team/22/relativelink/simple");
           DOM.dispatchEvent(native, DOM.createMouseEvent('click'));
           advance(fixture);
开发者ID:davewragg,项目名称:angular,代码行数:66,代码来源:integration_spec.ts

示例4: describe

  describe('dom adapter', () => {
    it('should not coalesque text nodes', () => {
      var el1 = el('<div>a</div>');
      var el2 = el('<div>b</div>');
      DOM.appendChild(el2, DOM.firstChild(el1));
      expect(DOM.childNodes(el2).length).toBe(2);

      var el2Clone = DOM.clone(el2);
      expect(DOM.childNodes(el2Clone).length).toBe(2);
    });

    it('should clone correctly', () => {
      var el1 = el('<div x="y">a<span>b</span></div>');
      var clone = DOM.clone(el1);

      expect(clone).not.toBe(el1);
      DOM.setAttribute(clone, 'test', '1');
      expect(stringifyElement(clone)).toEqual('<div test="1" x="y">a<span>b</span></div>');
      expect(DOM.getAttribute(el1, 'test')).toBeFalsy();

      var cNodes = DOM.childNodes(clone);
      var firstChild = cNodes[0];
      var secondChild = cNodes[1];
      expect(DOM.parentElement(firstChild)).toBe(clone);
      expect(DOM.nextSibling(firstChild)).toBe(secondChild);
      expect(DOM.isTextNode(firstChild)).toBe(true);

      expect(DOM.parentElement(secondChild)).toBe(clone);
      expect(DOM.nextSibling(secondChild)).toBeFalsy();
      expect(DOM.isElementNode(secondChild)).toBe(true);

    });

    it('should be able to create text nodes and use them with the other APIs', () => {
      var t = DOM.createTextNode('hello');
      expect(DOM.isTextNode(t)).toBe(true);
      var d = DOM.createElement('div');
      DOM.appendChild(d, t);
      expect(DOM.getInnerHTML(d)).toEqual('hello');
    });

    it('should set className via the class attribute', () => {
      var d = DOM.createElement('div');
      DOM.setAttribute(d, 'class', 'class1');
      expect(d.className).toEqual('class1');
    });

    it('should allow to remove nodes without parents', () => {
      var d = DOM.createElement('div');
      expect(() => DOM.remove(d)).not.toThrow();
    });

    if (DOM.supportsDOMEvents()) {
      describe('getBaseHref', () => {
        beforeEach(() => DOM.resetBaseElement());

        it('should return null if base element is absent',
           () => { expect(DOM.getBaseHref()).toBeNull(); });

        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/');
        });

        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).toEqual('/base');
        });
      });
    }


  });
开发者ID:kreo,项目名称:angular-2-bootstraping,代码行数:89,代码来源:dom_adapter_spec.ts

示例5: main

export function main() {
  var outputDefs = [];
  outputDefs.push({
    'getExpressions': () => interpretStatements(codegenStmts, 'getExpressions',
                                                new DynamicClassInstanceFactory()),
    'name': 'interpreted'
  });
  if (IS_DART || !DOM.supportsDOMEvents()) {
    // Our generator only works on node.js and Dart...
    outputDefs.push({'getExpressions': () => typed.getExpressions, 'name': 'typed'});
  }
  if (!IS_DART) {
    // Our generator only works on node.js and Dart...
    if (!DOM.supportsDOMEvents()) {
      outputDefs.push({'getExpressions': () => untyped.getExpressions, 'name': 'untyped'});
    }
    outputDefs.push({
      'getExpressions': () => jitStatements('output_emitter_spec', codegenStmts, 'getExpressions'),
      'name': 'jit'
    });
  }

  describe('output emitter', () => {
    outputDefs.forEach((outputDef) => {
      describe(`${outputDef['name']}`, () => {
        var expressions;
        beforeEach(() => { expressions = outputDef['getExpressions']()(); });

        it('should support literals', () => {
          expect(expressions['stringLiteral']).toEqual('Hello World!');
          expect(expressions['intLiteral']).toEqual(42);
          expect(expressions['boolLiteral']).toEqual(true);
          expect(expressions['arrayLiteral']).toEqual([0]);
          expect(expressions['mapLiteral']).toEqual({'key0': 0});
        });

        it('should support reading vars/keys/props', () => {
          expect(expressions['readVar']).toEqual('someValue');
          expect(expressions['readKey']).toEqual('someValue');
          expect(expressions['readPropExternalInstance']).toEqual('someValue');
          expect(expressions['readPropDynamicInstance']).toEqual('dynamicValue');
          expect(expressions['readGetterDynamicInstance'])
              .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue'});
        });

        it('should support writing to vars / keys / props', () => {
          expect(expressions['changedVar']).toEqual('changedValue');
          expect(expressions['changedKey']).toEqual('changedValue');
          expect(expressions['changedPropExternalInstance']).toEqual('changedValue');
          expect(expressions['changedPropDynamicInstance']).toEqual('changedValue');
        });

        it('should support declaring functions with parameters and return', () => {
          expect(expressions['fn']('someParam')).toEqual({'param': 'someParam'});
          expect(expressions['closureInDynamicInstance']('someParam'))
              .toEqual({'param': 'someParam', 'data': 'someValue', 'dynamicProp': 'dynamicValue'});
        });

        it('should support invoking functions and methods', () => {
          expect(expressions['invokeFn']).toEqual({'param': 'someParam'});
          expect(expressions['concatedArray']).toEqual([0, 1]);
          expect(expressions['invokeMethodExternalInstance'])
              .toEqual({'data': 'someValue', 'param': 'someParam'});
          expect(expressions['invokeMethodExternalInstanceViaBind'])
              .toEqual({'data': 'someValue', 'param': 'someParam'});
          expect(expressions['invokeMethodDynamicInstance'])
              .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
          expect(expressions['invokeMethodDynamicInstanceViaBind'])
              .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
        });

        it('should support conditionals', () => {
          expect(expressions['conditionalTrue']).toEqual('true');
          expect(expressions['conditionalFalse']).toEqual('false');
        });

        it('should support not', () => { expect(expressions['not']).toEqual(true); });

        it('should support reading external identifiers', () => {
          expect(expressions['externalTestIdentifier']).toBe(ExternalClass);
          expect(expressions['externalSrcIdentifier']).toBe(EventEmitter);
          expect(expressions['externalEnumIdentifier']).toBe(ViewType.HOST);
        });

        it('should support instantiating classes', () => {
          expect(expressions['externalInstance']).toBeAnInstanceOf(ExternalClass);
          // Note: toBeAnInstanceOf does not check super classes in Dart...
          expect(expressions['dynamicInstance'] instanceof ExternalClass).toBe(true);
        });

        describe('operators', () => {
          var ops;
          var aObj, bObj;
          beforeEach(() => {
            ops = expressions['operators'];
            aObj = new Object();
            bObj = new Object();
          });
          it('should support ==', () => {
            expect(ops['=='](aObj, aObj)).toBe(true);
//.........这里部分代码省略.........
开发者ID:844496869,项目名称:angular,代码行数:101,代码来源:output_emitter_spec.ts


注:本文中的angular2/src/platform/dom/dom_adapter.DOM.supportsDOMEvents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。