Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Sep 6, 2023
Merged

Conversation

ealush
Copy link
Owner

@ealush ealush commented Sep 5, 2023

Can be tested by:

npm install [email protected]

Add pending indication to the following:

  • Result summary (pendingCount)
  • Result selectors (isPending)
  • vest parser (pending)
  • classnames (pending)

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
Copy link

vercel bot commented Sep 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant