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


TypeScript DOM.supportsDOMEvents方法代码示例

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


在下文中一共展示了DOM.supportsDOMEvents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:TedSander,项目名称:angular,代码行数:52,代码来源:metadata_spec.ts

示例2: 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:TedSander,项目名称:angular,代码行数:89,代码来源:dom_adapter_spec.ts


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