mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 23:09:47 +00:00
Merge pull request #13444 from strapi/fix/yup-strapiID
Fix yup strapiID not working
This commit is contained in:
commit
98c8b53604
97
packages/core/utils/lib/__tests__/validators.test.js
Normal file
97
packages/core/utils/lib/__tests__/validators.test.js
Normal file
@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
const { yup } = require('../validators');
|
||||
|
||||
describe('validators', () => {
|
||||
describe('strapiID', () => {
|
||||
test.each([
|
||||
[0, true],
|
||||
['0', true],
|
||||
[1, true],
|
||||
['1', true],
|
||||
[undefined, true], // because it's not required
|
||||
[{}, false],
|
||||
[[], false],
|
||||
[null, false],
|
||||
])('yup.strapiID(): %s => %s', async (value, expectedResult) => {
|
||||
let result = true;
|
||||
try {
|
||||
await yup.strapiID().validate(value);
|
||||
} catch (e) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
expect(result).toBe(expectedResult);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[0, true],
|
||||
['0', true],
|
||||
[1, true],
|
||||
['1', true],
|
||||
[undefined, false],
|
||||
[{}, false],
|
||||
[[], false],
|
||||
[null, false],
|
||||
])('yup.strapiID().required(): %s => %s', async (value, expectedResult) => {
|
||||
let result = true;
|
||||
try {
|
||||
await yup
|
||||
.strapiID()
|
||||
.required()
|
||||
.validate(value);
|
||||
} catch (e) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
expect(result).toBe(expectedResult);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[0, true],
|
||||
['0', true],
|
||||
[1, true],
|
||||
['1', true],
|
||||
[undefined, true],
|
||||
[{}, false],
|
||||
[[], false],
|
||||
[null, true],
|
||||
])('yup.strapiID().nullable(): %s => %s', async (value, expectedResult) => {
|
||||
let result = true;
|
||||
try {
|
||||
await yup
|
||||
.strapiID()
|
||||
.nullable()
|
||||
.validate(value);
|
||||
} catch (e) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
expect(result).toBe(expectedResult);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[0, true],
|
||||
['0', true],
|
||||
[1, true],
|
||||
['1', true],
|
||||
[undefined, false],
|
||||
[{}, false],
|
||||
[[], false],
|
||||
[null, true],
|
||||
])('yup.strapiID().nullable().defined(): %s => %s', async (value, expectedResult) => {
|
||||
let result = true;
|
||||
try {
|
||||
await yup
|
||||
.strapiID()
|
||||
.nullable()
|
||||
.defined()
|
||||
.validate(value);
|
||||
} catch (e) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
expect(result).toBe(expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
@ -7,7 +7,7 @@ const utils = require('./string-formatting');
|
||||
const { YupValidationError } = require('./errors');
|
||||
const printValue = require('./print-value');
|
||||
|
||||
const MixedSchemaType = yup.mixed;
|
||||
const MixedSchemaType = yup.MixedSchema;
|
||||
|
||||
const isNotNilTest = value => !_.isNil(value);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user