How to use for-each - 10 common examples

To help you get started, we’ve selected a few for-each examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dominicbarnes / deku-forms / test / checkbox-field.js View on Github external
assert.node.hasClass(node.children[0].children[0], 'a');
      });
    });

    let fieldAttrs = {
      hint: 'a',
      // label: 'b',
      description: 'c',
      // error: 'd',
      hintClass: 'e',
      // labelClass: 'f',
      descriptionClass: 'g'
      // errorClass: 'h'
    };

    each(fieldAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the Field', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          assert.node.hasAttribute(node, attr, value);
        });
      });
    });

    describe('.error', function () {
      // TODO
    });

    describe('.label', function () {
      // TODO
    });
github dominicbarnes / deku-forms / test / input-field.js View on Github external
max: 50,
      maxlength: 50,
      min: 2,
      minlength: 2,
      name: 'test',
      pattern: '\d+',
      placeholder: 'test',
      readonly: true,
      required: true,
      size: 2,
      step: 2,
      type: 'number',
      value: 'hello world'
    };

    each(inputAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the input', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          let input = node.children[0];
          assert.node.hasAttribute(input, attr, value);
        });
      });
    });

    describe('.class', function () {
      it('should add the custom class', function () {
        let props = { class: 'MyField' };
        let node = mock.render({ props });
        assert.node.hasClass(node, 'MyField');
      });
github dominicbarnes / deku-forms / test / text-field.js View on Github external
let node = mock.render({ props });
        assert.node.hasClass(node.children[0], 'a');
      });
    });

    let textareaAttrs = {
      disabled: true,
      maxlength: 10,
      minlength: 2,
      name: 'test',
      placeholder: 'test',
      readonly: true,
      required: true
    };

    each(textareaAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the textarea', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          let input = node.children[0];
          assert.node.hasAttribute(input, attr, value);
        });
      });
    });

    let fieldAttrs = {
      hint: 'a',
      label: 'b',
      description: 'c',
      error: 'd',
      hintClass: 'e',
github dominicbarnes / deku-forms / test / select-field.js View on Github external
describe('with props', function () {
    let selectAttrs = {
      autofocus: true,
      disabled: true,
      name: 'test',
      placeholder: 'test',
      required: true,
      size: 2,
      value: 'hello world'
    };

    each(selectAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the Select', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          let select = node.children[0];
          assert.node.hasAttribute(select, attr, value);
        });
      });
    });

    describe('.class', function () {
      it('should add the custom class', function () {
        let props = { class: 'MyField' };
        let node = mock.render({ props });
        assert.node.hasClass(node, 'MyField');
      });
github dominicbarnes / deku-forms / test / checkbox-field.js View on Github external
describe('with props', function () {
    let inputAttrs = {
      autofocus: true,
      checked: true,
      name: 'test',
      required: true,
      value: 'hello world'
    };

    each(inputAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the input', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          let input = node.children[0].children[0];
          assert.node.hasAttribute(input, attr, value);
        });
      });
    });

    describe('.class', function () {
      it('should add the custom class', function () {
        let props = { class: 'MyField' };
        let node = mock.render({ props });
        assert.node.hasClass(node, 'MyField');
      });
github dominicbarnes / deku-forms / test / text-field.js View on Github external
let inputAttrs = {
      autofocus: true,
      disabled: true,
      maxlength: 10,
      minlength: 2,
      name: 'test',
      pattern: '\d+',
      placeholder: 'test',
      readonly: true,
      required: true,
      size: 2,
      value: 'hello world'
    };

    each(inputAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the input', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          let input = node.children[0];
          assert.node.hasAttribute(input, attr, value);
        });
      });
    });

    describe('.class', function () {
      it('should add the custom class', function () {
        let props = { class: 'MyField' };
        let node = mock.render({ props });
        assert.node.hasClass(node, 'MyField');
      });
github dominicbarnes / deku-forms / test / text-field.js View on Github external
});
      });
    });

    let fieldAttrs = {
      hint: 'a',
      label: 'b',
      description: 'c',
      error: 'd',
      hintClass: 'e',
      labelClass: 'f',
      descriptionClass: 'g',
      errorClass: 'h'
    };

    each(fieldAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the Field', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          assert.node.hasAttribute(node, attr, value);
        });
      });
    });

    describe('.id', function () {
      it('should add the id to the input', function () {
        let props = { id: 'test' };
        let node = mock.render({ props });
        let input = node.children[0];
        assert.node.hasAttribute(input, 'id', 'test');
      });
github dominicbarnes / deku-forms / test / select.js View on Github external
describe('with props', function () {
    let attrs = {
      class: 'a',
      disabled: true,
      id: 'a',
      name: 'b',
      required: true,
      size: 2
    };

    each(attrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the select', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          assert.node.hasAttribute(node, attr, value);
        });
      });
    });

    describe('.options', function () {
      it('should generate option elements from a simple array', function () {
        let options = [ 'a', 'b', 'c' ];
        let props = { options };
        let node = mock.render({ props });
        assert.node.hasChildren(node, function (node, x) {
          assert.node.isNode(node, 'option');
github dominicbarnes / deku-forms / test / select-field.js View on Github external
});
      });
    });

    let fieldAttrs = {
      hint: 'a',
      label: 'b',
      description: 'c',
      error: 'd',
      hintClass: 'e',
      labelClass: 'f',
      descriptionClass: 'g',
      errorClass: 'h'
    };

    each(fieldAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the Field', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          assert.node.hasAttribute(node, attr, value);
        });
      });
    });

    describe('.id', function () {
      it('should add the id to the input', function () {
        let props = { id: 'test' };
        let node = mock.render({ props });
        let input = node.children[0];
        assert.node.hasAttribute(input, 'id', 'test');
      });
github dominicbarnes / deku-forms / test / input-field.js View on Github external
assert.node.hasClass(node.children[0], 'a');
      });
    });

    let fieldAttrs = {
      hint: 'a',
      label: 'b',
      description: 'c',
      error: 'd',
      hintClass: 'e',
      labelClass: 'f',
      descriptionClass: 'g',
      errorClass: 'h'
    };

    each(fieldAttrs, function (value, attr) {
      describe(`.${attr}`, function () {
        it('should add the attribute to the Field', function () {
          let props = { [attr]: value };
          let node = mock.render({ props });
          assert.node.hasAttribute(node, attr, value);
        });
      });
    });

    describe('.id', function () {
      it('should add the id to the input', function () {
        let props = { id: 'test' };
        let node = mock.render({ props });
        let input = node.children[0];
        assert.node.hasAttribute(input, 'id', 'test');
      });

for-each

A better forEach

MIT
Latest version published 6 years ago

Package Health Score

68 / 100
Full package analysis

Popular for-each functions