Object versioning package (#153182)

This commit is contained in:
Sébastien Loix 2023-03-15 17:27:47 +00:00 committed by GitHub
parent 340ee10086
commit e8a20bb258
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1949 additions and 12 deletions

View file

@ -0,0 +1,32 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { validateVersion } from './utils';
describe('utils', () => {
describe('validateVersion()', () => {
[
{ input: '123', isValid: true, expected: 123 },
{ input: 123, isValid: true, expected: 123 },
{ input: 1.23, isValid: false, expected: null },
{ input: '123a', isValid: false, expected: null },
{ input: 'abc', isValid: false, expected: null },
{ input: undefined, isValid: false, expected: null },
{ input: null, isValid: false, expected: null },
{ input: [123], isValid: false, expected: null },
{ input: { 123: true }, isValid: false, expected: null },
{ input: () => 123, isValid: false, expected: null },
].forEach(({ input, expected, isValid }) => {
test(`validate: [${input}]`, () => {
const { result, value } = validateVersion(input);
expect(result).toBe(isValid);
expect(value).toBe(expected);
});
});
});
});