Skip to content

Commit

Permalink
patch(vest): isValid uses static summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Mar 28, 2022
1 parent a8484a8 commit 6446c19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/vest/src/core/suite/produce/genTestsSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assign from 'assign';

import { Severity, SeverityCount } from 'Severity';
import VestTest from 'VestTest';
import { isValid } from 'isValid';
import { shouldAddValidProp } from 'isValid';
import { useTestsFlat } from 'stateHooks';

/**
Expand All @@ -26,7 +26,7 @@ export default function genTestsSummary(): SuiteSummary {
summary
);

summary.valid = isValid();
summary.valid = shouldAddValidProp();

return countFailures(summary);
}
Expand All @@ -37,7 +37,7 @@ function appendToTest(tests: TestGroup, testObject: VestTest) {
tests[testObject.fieldName].valid =
tests[testObject.fieldName].valid === false
? false
: isValid(testObject.fieldName);
: shouldAddValidProp(testObject.fieldName);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion packages/vest/src/core/suite/produce/isValid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import invariant from 'invariant';
import { isNotEmpty, isEmpty } from 'isEmpty';

import ctx from 'ctx';
import { hasErrors } from 'hasFailures';
import { nonMatchingFieldName } from 'matchingFieldName';
import {
Expand All @@ -9,8 +11,16 @@ import {
useOmittedFields,
} from 'stateHooks';

// eslint-disable-next-line max-statements, complexity
export function isValid(fieldName?: string): boolean {
const { summary } = ctx.useX();

invariant(summary);

return Boolean(fieldName ? summary.tests?.[fieldName]?.valid : summary.valid);
}

// eslint-disable-next-line max-statements, complexity
export function shouldAddValidProp(fieldName?: string): boolean {
if (fieldIsOmitted(fieldName)) {
return true;
}
Expand Down

0 comments on commit 6446c19

Please sign in to comment.