Skip to content

Commit

Permalink
add(vest): isTested suite selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Dec 1, 2023
1 parent 91661a6 commit 31d7848
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/vest/src/suiteResult/selectors/__tests__/isTested.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import wait from 'wait';

import * as vest from 'vest';

describe('isTested', () => {
describe('When no field name is passed', () => {
describe('When suite has no tests', () => {
it('Should return false', () => {
const suite = vest.create(() => {});
suite();
// @ts-ignore - invalid input
expect(suite.isTested()).toBe(false);
});
});

describe('When suite has tests', () => {
it('Should return false', () => {
const suite = vest.create(() => {
vest.test('f1', () => {});
});
suite();
// @ts-ignore - invalid input
expect(suite.isTested()).toBe(false);
});
});
});

describe('When suite has no tests', () => {
it('Should return false', () => {
const suite = vest.create(() => {});
suite();
expect(suite.isTested('f1')).toBe(false);
});
});

describe('When suite has tests', () => {
describe('When field has no tests', () => {
it('Should return false', () => {
const suite = vest.create(() => {
vest.test('f1', () => {});
});
suite();
expect(suite.isTested('f2')).toBe(false);
});
});

describe('When field has tests', () => {
it('Should return true', () => {
const suite = vest.create(() => {
vest.test('f1', () => {});
});
suite();
expect(suite.isTested('f1')).toBe(true);
});
});
});

describe('When async test is pending', () => {
it('Should return false', async () => {
const suite = vest.create(() => {
vest.test('f1', async () => {
await wait(100);
});
});
suite();
expect(suite.isTested('f1')).toBe(true);
});
});
});
8 changes: 8 additions & 0 deletions packages/vest/src/suiteResult/selectors/suiteSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export function bindSuiteSelectors<F extends TFieldName, G extends TGroupName>(
isPending: (...args: Parameters<SuiteSelectors<F, G>['isPending']>) => {
return get().isPending(...args);
},
isTested: (...args: Parameters<SuiteSelectors<F, G>['isTested']>) =>
get().isTested(...args),
isValid: (...args: Parameters<SuiteSelectors<F, G>['isValid']>) =>
get().isValid(...args),
isValidByGroup: (
Expand All @@ -69,6 +71,7 @@ export function suiteSelectors<F extends TFieldName, G extends TGroupName>(
hasWarnings,
hasWarningsByGroup,
isPending,
isTested,
isValid,
isValidByGroup,
};
Expand Down Expand Up @@ -108,6 +111,10 @@ export function suiteSelectors<F extends TFieldName, G extends TGroupName>(
return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
}

function isTested(fieldName: F): boolean {
return isPositive(summary.tests[fieldName]?.testCount);
}

function hasWarningsByGroup<G extends TGroupName>(
groupName: G,
fieldName?: F
Expand Down Expand Up @@ -203,6 +210,7 @@ export interface SuiteSelectors<F extends TFieldName, G extends TGroupName> {
hasWarnings(fieldName?: F): boolean;
hasErrorsByGroup(groupName: G, fieldName?: F): boolean;
hasWarningsByGroup(groupName: G, fieldName?: F): boolean;
isTested(fieldName: F): boolean;
isPending(fieldName?: F): boolean;
isValid(fieldName?: F): boolean;
isValidByGroup(groupName: G, fieldName?: F): boolean;
Expand Down

2 comments on commit 31d7848

@vercel
Copy link

@vercel vercel bot commented on 31d7848 Dec 1, 2023

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 – ./website

vest-git-latest-ealush.vercel.app
www.vestjs.dev
vest-ealush.vercel.app
vest.vercel.app
vestjs.dev

@vercel
Copy link

@vercel vercel bot commented on 31d7848 Dec 1, 2023

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.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.