ealush / vest

Vest ✅ Declarative validations framework
https://vestjs.dev/
MIT License
2.57k stars 84 forks source link

Add pending indication to all of Vest's APIs #1067

Closed ealush closed 1 year ago

ealush commented 1 year ago

Can be tested by:

npm install vest@5.0.0-next-20230905-5c95

Add pending indication to the following:

Result Object:

{
  'valid': false,           // Whether the suite as a whole is valid or not
  'errorCount': 0,          // Overall count of errors in the suite
  'warnCount': 0,           // Overall count of warnings in the suite
  'testCount': 0,           // Overall test count for the suite (passing, failing and warning)
+  'pendingCount': 0,        // Overall count of unresolved async tests in the suite
  'tests': {                // An object containing all non-skipped tests
    ['fieldName']: {        // Name of each field
      'errorCount': 0,      // Error count per field
      'errors': [],         // Array of error messages fer field (may be undefined)
      'warnings': [],       // Array of warning messages fer field (may be undefined)
      'warnCount': 0,       // Warning count per field
      'testCount': 0,       // Overall test count for the field (passing, failing and warning)
+      'pendingCount': 0,    // Overall count of unresolved async tests in the current field
      'valid': false,       // Field specific validity
    },
    'groups': {             // An object containing groups declared in the suite
      ['fieldName']: {      // Subset of res.tests[fieldName]
        /*... */            // only containing tests that ran within the group
      }
    }
  }
  'errors': [               // An array containing all the errors occurred in order
    {
      fieldName: "fieldname",
      groupName: undefined, // or whatever group we're in
      message: "validation message"
    },
  ],
  'warnings': [{            // An array containing all the warnings occurred in order
      fieldName: "fieldname",
      groupName: undefined, // or whatever group we're in
      message: "validation message"
    }]
}

isPending selector

Returns whether the suite, or a specific field are pending or not. A suite is considered pending if it has unresolved async tests.

Returns true if the suite is pending, false otherwise.

const suite = vest.create(() => {
  test('username', 'Username is already taken', async () => {
    await someServerCall();
  });
});

result.isPending();

suite.isPending();

suite.get().isPending();

result.isPending('username');

suite.isPending('username');

suite.get().isPending('username');

classnames


import classnames from 'vest/classnames';
import suite from './suite';

const res = suite(data);

const cn = classnames(res, {
  untested: 'is-untested', // will only be applied if the provided field did not run yet
  tested: 'some-tested-class', // will only be applied if the provided field did run
  invalid: 'my_invalid_class', // will only be applied if the provided field ran at least once and has an error
  valid: 'my_valid_class', // will only be applied if the provided field ran at least once does not have errors or warnings
  warning: 'my_warning_class', // will only be applied if the provided field ran at least once and has a warning
+   pending: 'my_pending_class', // will only be applied if the provided field has pending async tests
});

const fieldOneClasses = cn('field_1'); // "is-untested"
const fieldTwoClasses = cn('field_2'); // "some-tested-class my_invalid_class"
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2023 2:43pm
vest-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2023 2:43pm