Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

patch(vest): getFailures uses static summary object

# The commit message #2 will be skipped:

# initial commit
  • Loading branch information
ealush committed Mar 28, 2022
1 parent 3f9811e commit 31727a0
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 251 deletions.
2 changes: 2 additions & 0 deletions packages/vest/src/core/ctx/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IsolateKeys, IsolateTypes } from 'IsolateTypes';
import { Modes } from 'Modes';
import VestTest from 'VestTest';
import type { TStateRef } from 'createStateRef';
import { SuiteSummary } from 'genTestsSummary';

export default createContext<CTXType>((ctxRef, parentContext) =>
parentContext
Expand Down Expand Up @@ -59,4 +60,5 @@ type CTXType = {
};
emit: (event: string, ...args: any[]) => void;
};
summary?: SuiteSummary;
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe.each(Object.keys(methods))('produce method: %s', methodName => {
expect(produceMethod().hasWarnings('field_5')).toBe(true);
expect(produceMethod().getErrors()).toEqual({
field_1: ['message', 'failure_message', 'failure_message with group'],
field_2: [],
field_3: ['msg'],
});
expect(produceMethod().getWarnings()).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/suite/produce/genTestsSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export type SuiteSummary = {
valid: boolean;
} & SummaryBase;

type TestGroup = Record<string, SingleTestSummary>;
export type TestGroup = Record<string, SingleTestSummary>;

type SingleTestSummary = SummaryBase & {
errors: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Object {
"field_2_failure message 1",
"field_2_failure message 3",
],
"field_3": Array [],
"v": Array [],
"x": Array [],
}
`;

Expand All @@ -36,6 +39,7 @@ Object {
"field_2_failure message 1",
"field_2_failure message 3",
],
"field_3": Array [],
}
`;

Expand All @@ -52,10 +56,14 @@ exports[`collectFailureMessages getErrorsByGroup with field name Should match sn

exports[`collectFailureMessages getWarnings When no options passed should match snapshot 1`] = `
Object {
"field_1": Array [],
"field_2": Array [
"field_2_warning message 2",
"field_2_warning message 3",
],
"field_3": Array [],
"v": Array [],
"x": Array [],
}
`;

Expand All @@ -72,9 +80,11 @@ exports[`collectFailureMessages getWarnings When specific field requested Should

exports[`collectFailureMessages getWarningsByGroup Should match snapshot 1`] = `
Object {
"field_1": Array [],
"field_2": Array [
"field_2_warning message 3",
],
"field_3": Array [],
}
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// TODO: Verify this test file is not needed and delete it
import { dummyTest } from '../../../../../../testUtils/testDummy';

import { Severity } from 'Severity';
import VestTest from 'VestTest';
import collectFailureMessages from 'collectFailureMessages';
import create from 'create';
import group from 'group';
import { SuiteResult } from 'produceSuiteResult';
Expand All @@ -26,6 +23,7 @@ describe('collectFailureMessages', () => {
expect(result).toEqual({
field_1: [],
field_2: ['field_2_failure message 1', 'field_2_failure message 3'],
field_3: [],
});
});

Expand All @@ -34,13 +32,7 @@ describe('collectFailureMessages', () => {
});

it('Should return an object with an empty array when selected field has no errors', () => {
expect(
collectFailureMessages(
Severity.ERRORS,
[new VestTest('field_1', jest.fn(), { message: 'error_message' })],
{ fieldName: 'field_1' }
)
).toEqual({ field_1: [] });
expect(res.getErrors('v')).toEqual([]);
});

describe('getErrors', () => {
Expand Down Expand Up @@ -120,6 +112,11 @@ describe('collectFailureMessages', () => {
'group_1'
);
dummyTest.failing('field_2', 'field_2_failure message 3', 'group_1');
dummyTest.passing('v');

group('group_2', () => {
dummyTest.passing('x');
});
});
suite();
res = suite.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ describe.each(Object.keys(methods))('produce method: %s', methodName => {
});
describe('When no errors', () => {
describe('When no parameters passed', () => {
itWithContext('Should return an empty object', () => {
setTestObjects(dummyTest.passing(), dummyTest.passing());
expect(produceMethod().getErrors()).toEqual({});
itWithContext('Should return an object with empty error arrays', () => {
setTestObjects(dummyTest.passing('f1'), dummyTest.passing('f2'));
expect(produceMethod().getErrors()).toEqual({
f1: [],
f2: [],
});
});
});
describe('When requesting a fieldName', () => {
Expand Down Expand Up @@ -88,8 +91,11 @@ describe.each(Object.keys(methods))('produce method: %s', methodName => {
describe('When no warnings', () => {
describe('When no parameters passed', () => {
itWithContext('Should return an empty object', () => {
setTestObjects(dummyTest.passing(), dummyTest.passing());
expect(produceMethod().getWarnings()).toEqual({});
setTestObjects(dummyTest.passing('x'), dummyTest.passing('y'));
expect(produceMethod().getWarnings()).toEqual({
x: [],
y: [],
});
});
});
describe('When requesting a fieldName', () => {
Expand Down
Loading

0 comments on commit 31727a0

Please sign in to comment.