Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jun 10, 2021
1 parent fbd3ace commit 35e4279
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ValidationFuncArg } from 'src/plugins/es_ui_shared/static/forms/hook_form_lib';

import { emptyArrayItem } from './field_validators';

describe('emptyArrayItem', () => {
const MESSAGE = 'error message';
const defaultArgs: ValidationFuncArg<FormData, unknown> = {
path: '',
form: {
getFormData: jest.fn(),
getFields: jest.fn(),
},
formData: {} as FormData,
errors: [],
value: undefined,
};

test('should return an error when value is an empty string', () => {
expect(emptyArrayItem(MESSAGE)({ ...defaultArgs, value: ' ' })).toEqual({
code: 'ERR_INVALID_CHARS',
message: MESSAGE,
});
});
test('should return undefined when value is not a string', () => {
expect(emptyArrayItem(MESSAGE)({ ...defaultArgs, value: 9999 })).toBe(undefined);
});
test('should return undefined when value is not an empty string', () => {
expect(emptyArrayItem(MESSAGE)({ ...defaultArgs, value: 'non-empty string' })).toBe(undefined);
});
});

0 comments on commit 35e4279

Please sign in to comment.