@gitlab/ui
Version:
GitLab UI Components
30 lines (25 loc) • 827 B
JavaScript
import { required } from './validators';
const TEST_FAIL_MESSAGE = 'Yo test failed!';
describe('components/base/form/form_fields/validators', () => {
// note: We used the `factory` to build required, so we implicitly test `factory` heere
describe('required', () => {
let validator;
beforeEach(() => {
validator = required(TEST_FAIL_MESSAGE);
});
it.each`
input | output
${''} | ${TEST_FAIL_MESSAGE}
${null} | ${TEST_FAIL_MESSAGE}
${undefined} | ${TEST_FAIL_MESSAGE}
${'123'} | ${''}
${{}} | ${''}
${0} | ${''}
${1} | ${''}
${true} | ${''}
${false} | ${''}
`('with $input, returns $output', ({ input, output }) => {
expect(validator(input)).toBe(output);
});
});
});