mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
tests: don't use multiple expect.stringContaining in one statement (#4158)
Apparently Jest doesn't like it when you use multiple stringContaining statements for one property. Only the last `stringContaining` statement is evaluated while the others are ignored. This means that a lot of these assertions were never checked. To fix that, I've extracted them into separate assertions.
This commit is contained in:
parent
b04545c25f
commit
d49626133e
@ -64,11 +64,12 @@ describe('OpenAPI error conversion', () => {
|
|||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description:
|
||||||
// it tells the user that the property is required
|
// it tells the user that the property is required
|
||||||
expect.stringContaining('required') &&
|
expect.stringContaining('required'),
|
||||||
// it tells the user the name of the missing property
|
|
||||||
expect.stringContaining(error.params.missingProperty),
|
|
||||||
path: 'enabled',
|
path: 'enabled',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it tells the user the name of the missing property
|
||||||
|
expect(result.description).toContain(error.params.missingProperty);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Gives useful error messages for type errors', () => {
|
it('Gives useful error messages for type errors', () => {
|
||||||
@ -92,11 +93,12 @@ describe('OpenAPI error conversion', () => {
|
|||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description:
|
||||||
// it provides the message
|
// it provides the message
|
||||||
expect.stringContaining(error.message) &&
|
expect.stringContaining(error.message),
|
||||||
// it tells the user what they provided
|
|
||||||
expect.stringContaining(JSON.stringify(parameterValue)),
|
|
||||||
path: 'parameters',
|
path: 'parameters',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it tells the user what they provided
|
||||||
|
expect(result.description).toContain(JSON.stringify(parameterValue));
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['.body', '.body.subObject'])(
|
it.each(['.body', '.body.subObject'])(
|
||||||
@ -158,12 +160,11 @@ describe('OpenAPI error conversion', () => {
|
|||||||
})(error);
|
})(error);
|
||||||
|
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description: expect.stringContaining(error.params.pattern),
|
||||||
expect.stringContaining(error.params.pattern) &&
|
|
||||||
expect.stringContaining('description') &&
|
|
||||||
expect.stringContaining(requestDescription),
|
|
||||||
path: 'description',
|
path: 'description',
|
||||||
});
|
});
|
||||||
|
expect(result.description).toContain('description');
|
||||||
|
expect(result.description).toContain(requestDescription);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Gives useful min/maxlength error messages', () => {
|
it('Gives useful min/maxlength error messages', () => {
|
||||||
@ -187,12 +188,13 @@ describe('OpenAPI error conversion', () => {
|
|||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description:
|
||||||
// it tells the user what the limit is
|
// it tells the user what the limit is
|
||||||
expect.stringContaining(error.params.limit.toString()) &&
|
expect.stringContaining(error.params.limit.toString()),
|
||||||
// it tells the user which property it pertains to
|
|
||||||
expect.stringContaining('description') &&
|
|
||||||
// it tells the user what they provided
|
|
||||||
expect.stringContaining(requestDescription),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it tells the user which property it pertains to
|
||||||
|
expect(result.description).toContain('description');
|
||||||
|
// it tells the user what they provided
|
||||||
|
expect(result.description).toContain(requestDescription);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handles numerical min/max errors', () => {
|
it('Handles numerical min/max errors', () => {
|
||||||
@ -218,14 +220,15 @@ describe('OpenAPI error conversion', () => {
|
|||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description:
|
||||||
// it tells the user what the limit is
|
// it tells the user what the limit is
|
||||||
expect.stringContaining(error.params.limit.toString()) &&
|
expect.stringContaining(error.params.limit.toString()),
|
||||||
// it tells the user what kind of comparison it performed
|
|
||||||
expect.stringContaining(error.params.comparison) &&
|
|
||||||
// it tells the user which property it pertains to
|
|
||||||
expect.stringContaining('newprop') &&
|
|
||||||
// it tells the user what they provided
|
|
||||||
expect.stringContaining(propertyValue.toString()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it tells the user what kind of comparison it performed
|
||||||
|
expect(result.description).toContain(error.params.comparison);
|
||||||
|
// it tells the user which property it pertains to
|
||||||
|
expect(result.description).toContain('newprop');
|
||||||
|
// it tells the user what they provided
|
||||||
|
expect(result.description).toContain(propertyValue.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handles multiple errors', () => {
|
it('Handles multiple errors', () => {
|
||||||
@ -292,14 +295,14 @@ describe('OpenAPI error conversion', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(error).toMatchObject({
|
expect(error).toMatchObject({
|
||||||
description:
|
description: expect.stringContaining(
|
||||||
expect.stringContaining(
|
|
||||||
openApiError.params.additionalProperty,
|
openApiError.params.additionalProperty,
|
||||||
) &&
|
),
|
||||||
expect.stringMatching('/\broot\b/i') &&
|
|
||||||
expect.stringMatching(/\badditional properties\b/i),
|
|
||||||
path: 'bogus',
|
path: 'bogus',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(error.description).toMatch(/\broot\b/i);
|
||||||
|
expect(error.description).toMatch(/\badditional properties\b/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gives useful messages for nested properties', () => {
|
it('gives useful messages for nested properties', () => {
|
||||||
@ -321,14 +324,14 @@ describe('OpenAPI error conversion', () => {
|
|||||||
const error = fromOpenApiValidationError(request2)(openApiError);
|
const error = fromOpenApiValidationError(request2)(openApiError);
|
||||||
|
|
||||||
expect(error).toMatchObject({
|
expect(error).toMatchObject({
|
||||||
description:
|
description: expect.stringContaining('nestedObject.nested2'),
|
||||||
expect.stringContaining('nestedObject.nested2') &&
|
|
||||||
expect.stringContaining(
|
|
||||||
openApiError.params.additionalProperty,
|
|
||||||
) &&
|
|
||||||
expect.stringMatching(/\badditional properties\b/i),
|
|
||||||
path: 'nestedObject.nested2.extraPropertyName',
|
path: 'nestedObject.nested2.extraPropertyName',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(error.description).toContain(
|
||||||
|
openApiError.params.additionalProperty,
|
||||||
|
);
|
||||||
|
expect(error.description).toMatch(/\badditional properties\b/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -348,11 +351,11 @@ describe('OpenAPI error conversion', () => {
|
|||||||
})(error);
|
})(error);
|
||||||
|
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description: expect.stringMatching(/\bnestedObject.a.b\b/),
|
||||||
expect.stringMatching(/\bnestedObject.a.b\b/) &&
|
|
||||||
expect.stringContaining('[]'),
|
|
||||||
path: 'nestedObject.a.b',
|
path: 'nestedObject.a.b',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(result.description).toContain('[]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handles deeply nested properties on referenced schemas', () => {
|
it('Handles deeply nested properties on referenced schemas', () => {
|
||||||
@ -371,11 +374,11 @@ describe('OpenAPI error conversion', () => {
|
|||||||
})(error);
|
})(error);
|
||||||
|
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
description:
|
description: expect.stringContaining(illegalValue),
|
||||||
expect.stringMatching(/\bnestedObject.a.b\b/) &&
|
|
||||||
expect.stringContaining(illegalValue),
|
|
||||||
path: 'nestedObject.a.b',
|
path: 'nestedObject.a.b',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(result.description).toMatch(/\bnestedObject.a.b\b/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -405,10 +408,9 @@ describe('Error serialization special cases', () => {
|
|||||||
validationThrewAnError = true;
|
validationThrewAnError = true;
|
||||||
const convertedError = fromLegacyError(e);
|
const convertedError = fromLegacyError(e);
|
||||||
|
|
||||||
expect(convertedError.toJSON()).toMatchObject({
|
const result = convertedError.toJSON();
|
||||||
message:
|
expect(result).toMatchObject({
|
||||||
expect.stringContaining('validation error') &&
|
message: expect.stringContaining('details'),
|
||||||
expect.stringContaining('details'),
|
|
||||||
details: [
|
details: [
|
||||||
{
|
{
|
||||||
description:
|
description:
|
||||||
@ -416,6 +418,7 @@ describe('Error serialization special cases', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
expect(result.message).toContain('validation');
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(validationThrewAnError).toBeTruthy();
|
expect(validationThrewAnError).toBeTruthy();
|
||||||
|
Loading…
Reference in New Issue
Block a user