Skip to content

Commit

Permalink
patch(vest): isValid calculation without relying on result object
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Mar 9, 2022
1 parent e13b558 commit bc85119
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 10 additions & 6 deletions packages/vest/src/core/suite/produce/isValid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isNotEmpty, isEmpty } from 'isEmpty';

import { hasErrors } from 'hasFailures';
import { nonMatchingFieldName } from 'matchingFieldName';
import type { SuiteResult } from 'produceSuiteResult';
import {
useTestsFlat,
useAllIncomplete,
Expand All @@ -10,12 +10,12 @@ import {
} from 'stateHooks';

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

if (result.hasErrors(fieldName)) {
if (hasErrors(fieldName)) {
return false;
}

Expand All @@ -25,7 +25,7 @@ export function isValid(result: SuiteResult, fieldName?: string): boolean {
return false;
}

if (fieldDoesNotExist(result, fieldName)) {
if (fieldDoesNotExist(fieldName)) {
return false;
}

Expand Down Expand Up @@ -59,8 +59,12 @@ function hasNonOptionalIncomplete(fieldName?: string) {
);
}

function fieldDoesNotExist(result: SuiteResult, fieldName?: string): boolean {
return !!fieldName && isEmpty(result.tests[fieldName]);
function fieldDoesNotExist(fieldName?: string): boolean {
const testObjects = useTestsFlat();
return (
!!fieldName &&
!testObjects.find(testObject => testObject.fieldName === fieldName)
);
}

function noMissingTests(fieldName?: string): boolean {
Expand Down
4 changes: 1 addition & 3 deletions packages/vest/src/core/suite/produce/produceSuiteResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export function produceSuiteResult(): SuiteResult {
hasErrorsByGroup: ctx.bind(ctxRef, hasErrorsByGroup),
hasWarnings: ctx.bind(ctxRef, hasWarnings),
hasWarningsByGroup: ctx.bind(ctxRef, hasWarningsByGroup),
isValid: ctx.bind(ctxRef, (fieldName?: string) =>
isValid(produceSuiteResult(), fieldName)
),
isValid: ctx.bind(ctxRef, isValid),
suiteName,
});
})
Expand Down

1 comment on commit bc85119

@vercel
Copy link

@vercel vercel bot commented on bc85119 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-website.vercel.app
vest-next-ealush.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next.vercel.app

Please sign in to comment.