// @flow
/* eslint-env jest */
import arrayOf from '../arrayOf';

describe('rules.arrayOf', () => {
  it('should return array of validation errors', () => {
    expect(arrayOf('elements', [{}], { name: { required: true } })).toEqual(
      [{ name: { rule: 'required', value: undefined, field: 'name', config: { required: true } } }]
    );
  });

  it('should return correct with nested arrayOf', () => {
    const options = {
      name: { length: { max: 10 } },
      nestedValues: {
        arrayOf: { key: { numeric: { min: 0 } }, value: { length: { min: 3 } } },
      },
    };

    const output = arrayOf(
      'fields',
      [{ name: 'Test 1', nestedValues: [{ key: 'NaN', value: 'Value' }] }],
      options
    );

    const expectedOutput = [{
      'nestedValues[0].key': {
        field: 'nestedValues[0].key',
        rule: 'numeric',
        value: 'NaN',
        config: { numeric: { min: 0 } },
      },
    }];

    expect(output).toEqual(expectedOutput);
  });
});

@@ -57,16 +57,52 @@
 rrayOf';
+%0Aimport %7B validator %7D from '../../';
 %0A%0Adescri
@@ -251,16 +251,27 @@
 true %7D %7D
+, validator
 )).toEqu
@@ -759,16 +759,33 @@
  options
+,%0A      validator
 %0A    );%0A

Change test to reflect that arrayOf needs a validator