• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mocha-jsdom.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mocha-jsdom.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: jsdom

describe('LabelType', () => {
  var $:JQueryStatic;

  if (typeof window === 'undefined') {
    jsdom();
  }

  before(() => {
    $ = require('jquery');
  });


  describe('render', () => {

    it('should render an empty label element', () => {
      var $label:JQuery;
      var labelType = new LabelType();
      labelType.render();

      $label = $(labelType.el);

      assert.equal($label.length, 1);
      assert.equal($label.text().trim(), '');
    });

    it('should render a label element with text', () => {
      var $label:JQuery;
      var labelType = new LabelType({
        data: 'foo'
      });
      labelType.render();

      $label = $(labelType.el);

      assert.equal($label.length, 1);
      assert.equal($label.text().trim(), 'foo');
    });

  });

  describe('getData', () => {

    it('should return the label text', () => {
      var $label:JQuery;
      var labelType = new LabelType({
        data: 'foo'
      });
      labelType.render();

      $label = $(labelType.el);

      assert.equal(labelType.getData(), 'foo');

      $label.text('shazaam');
      assert.equal(labelType.getData(), 'shazaam');

      labelType.setData('kablooey');
      assert.equal(labelType.getData(), 'kablooey');
    });

  });

  describe('setData', () => {

    it('should set the label text', () => {
      var $label:JQuery;
      var labelType = new LabelType();
      labelType.render();

      labelType.setData('shazaam');

      $label = $(labelType.el);
      assert.equal($label.text(), 'shazaam');
    });

  });

});
开发者ID:aerisweather,项目名称:FormTypes,代码行数:78,代码来源:LabelTypeTest.ts


示例2: TextType

describe('GroupType', () => {
  var $:JQueryStatic;

  if (typeof window === 'undefined') {
    jsdom();
  }

  before(() => {
    $ = require('jquery');
  });

  describe('render', () => {

    it('should render an empty HTML div element', () => {
      var groupType = new GroupType();
      var $group:JQuery;

      groupType.render();
      $group = $(groupType.el);

      assert.equal($group.prop('tagName').toLowerCase(), 'div', 'Expected div element to exist');
      assert.equal($group.children().length, 0, 'Expected group to have no children');
    });

    it('should render child form types', () => {
      var $group:JQuery, $inputs:JQuery;
      var groupType = new GroupType({
        children: [
          new TextType({
            name: 'fooInput',
            data: 'foo'
          }),
          new TextType({
            name: 'barInput',
            data: 'bar'
          })
        ]
      });

      $group = $(groupType.render().el);
      $inputs = $group.find('input');

      assert.equal($inputs.length, 2,
        'Expected 2 child inputs to be rendered');

      assert.equal($inputs.eq(0).attr('name'), 'fooInput');
      assert.equal($inputs.eq(1).attr('name'), 'barInput');

      assert.equal($inputs.eq(0).val(), 'foo');
      assert.equal($inputs.eq(1).val(), 'bar');
    });

  });

  describe('removeChild', () => {

    it('should remove a child element from the dom', () => {
      var child:TextType;
      var groupType = new GroupType({
        children: [
          child = new TextType({
            name: 'fooInput',
            data: 'foo'
          })
        ]
      });

      groupType.render();

      assert.equal($(groupType.el).find(child.el).length, 1, 'Child should have a parent element (baseline)');

      groupType.removeChild(child);

      assert.equal($(groupType.el).find(child.el).length, 0, 'Child should not have a parent element');
    });

    it('should not complain if the GroupType is not rendered', () => {
      var child:TextType;
      var groupType = new GroupType({
        children: [
          child = new TextType({
            name: 'fooInput',
            data: 'foo'
          })
        ]
      });

      groupType.removeChild(child);
    });

    it('should not complain if the child element was closed independently', () => {
      var child:TextType;
      var groupType = new GroupType({
        children: [
          child = new TextType({
            name: 'fooInput',
            data: 'foo'
          })
        ]
      });
//.........这里部分代码省略.........
开发者ID:aerisweather,项目名称:FormTypes,代码行数:101,代码来源:GroupTypeTest.ts


示例3: jsdom

describe('MultiChoiceType', () => {
  var $:JQueryStatic;

  if (typeof window === 'undefined') {
    jsdom();
  }

  before(() => {
    $ = require('jquery');
    ServiceContainer.HtmlEvents = require('../../Util/JQueryHtmlEvents');
  });

  describe('render', () => {

    it('should create checkboxes for each choice', () => {
      var $checkboxes:JQuery;
      var multiChoiceType = new MultiChoiceType({
        choices: {
          us: 'United States',
          ca: 'Canada'
        }
      });

      multiChoiceType.render();
      $checkboxes = $(multiChoiceType.el).find('input[type=checkbox]');

      assert.equal($checkboxes.length, 2,
        'Should have rendered 2 checkboxes');

      assert.equal($checkboxes.filter('[value="us"]').length, 1);
      assert.equal($checkboxes.filter('[value="ca"]').length, 1);
    });

    it('should set the name of the checkbox to the data value', () => {
      var $checkboxes:JQuery;
      var multiChoiceType = new MultiChoiceType({
        choices: {
          us: 'United States',
          ca: 'Canada'
        }
      });

      multiChoiceType.render();
      $checkboxes = $(multiChoiceType.el).find('input[type=checkbox]');

      assert.equal($checkboxes.filter('[name="us"]').length, 1);
      assert.equal($checkboxes.filter('[name="ca"]').length, 1);
    });

    it('should render labels for each checkbox', () => {
      var $checkboxes:JQuery, $scope:JQuery
      var $usLabel:JQuery, $caLabel:JQuery;
      var usCheckboxId:string, caCheckboxId:string;

      var multiChoiceType = new MultiChoiceType({
        choices: {
          us: 'United States',
          ca: 'Canada'
        }
      });

      multiChoiceType.render();
      $scope = $(multiChoiceType.el);
      $checkboxes = $scope.find('input[type=checkbox]');

      usCheckboxId = $checkboxes.filter('[value="us"]').attr('id');
      caCheckboxId = $checkboxes.filter('[value="ca"]').attr('id');

      $usLabel = $scope.find('label[for="' + usCheckboxId + '"]');
      $caLabel = $scope.find('label[for="' + caCheckboxId + '"]');
      assert.equal($usLabel.length, 1, 'Should have a label for the US checkbox');
      assert.equal($caLabel.length, 1, 'Should have a label for the Canada checkbox');

      assert.equal($usLabel.text().trim(), 'United States');
      assert.equal($caLabel.text().trim(), 'Canada');
    });

    it('should select the options specified in `data`', () => {
      var $checkboxes:JQuery, $scope:JQuery;

      var multiChoiceType = new MultiChoiceType({
        choices: {
          us: 'United States',
          ca: 'Canada',
          fr: 'France'
        },
        data: ['us', 'fr']
      });

      multiChoiceType.render();
      $scope = $(multiChoiceType.el);
      $checkboxes = $scope.find('input[type=checkbox]');

      assert($checkboxes.filter('[value="us"]').is(':checked'), 'Expected US checkbox to be checked');
      assert(!$checkboxes.filter('[value="ca"]').is(':checked'), 'Expected CA checkbox not to be checked');
      assert($checkboxes.filter('[value="fr"]').is(':checked'), 'Expected FR checkbox to be checked');
    });

  });

//.........这里部分代码省略.........
开发者ID:aerisweather,项目名称:FormTypes,代码行数:101,代码来源:MultiChoiceTypeTest.ts


示例4: TextType

describe('FormType', () => {
  var $:JQueryStatic;

  if (typeof window === 'undefined') {
    jsdom();
  }

  before(() => {
    $ = require('jquery');
    ServiceContainer.HtmlEvents = require('../../Util/JQueryHtmlEvents');
  });

  describe('render', () => {

    it('should render an empty HTML form', () => {
      var formType = new FormType();
      var $form;

      formType.render();
      $form = $(formType.el);

      assert.equal($form.prop('tagName').toLowerCase(), 'form', 'Expected form element to exist');
      assert.equal($form.children().length, 0, 'Expected form to have no children');
    });

    it('should render child form types', () => {
      var $form:JQuery, $inputs:JQuery;
      var formType = new FormType({
        children: [
          new TextType({
            name: 'fooInput',
            data: 'foo'
          }),
          new TextType({
            name: 'barInput',
            data: 'bar'
          })
        ]
      });

      $form = $(formType.render().el);
      $inputs = $form.find('input');

      assert.equal($inputs.length, 2,
        'Expected 2 child inputs to be rendered');

      assert.equal($inputs.eq(0).attr('name'), 'fooInput');
      assert.equal($inputs.eq(1).attr('name'), 'barInput');

      assert.equal($inputs.eq(0).val(), 'foo');
      assert.equal($inputs.eq(1).val(), 'bar');
    });

  });

  describe('`submit` event', () => {

    it('should emit when you submit the form', () => {
      var onSubmit = sinon.spy();
      var $form:JQuery;
      var formType = new FormType();

      formType.render();
      $form = $(formType.el);

      $form.on('submit', (evt:JQueryEventObject) => {
        onSubmit();
        evt.preventDefault();
      });
      $form.submit();

      assert(onSubmit.called, 'Expected onSubmit listener to have been called.');
    });

  });

  describe('functional tests', () => {

    it('should swap out child types', () => {
      var $form:JQuery, $countrySelect:JQuery;
      var usForm = new FormType({
        name: 'usForm',
        children: [
          new ChoiceType({
            name: 'sodaOrPop',
            choices: {
              'soda': 'It\' called soda',
              'pop': 'No, it\'s caled pop.'
            }
          })
        ]
      });
      var franceForm = new FormType({
        name: 'franceForm',
        children: [
          new ChoiceType({
            name: 'croissantOrBaguette',
            choices: {
              'croissant': 'Croissant',
              'baguette': 'Baguette'
//.........这里部分代码省略.........
开发者ID:aerisweather,项目名称:FormTypes,代码行数:101,代码来源:FormTypeTest.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mocha-typescript.suite函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mocha-each.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap