Skip to content

Commit

Permalink
tests(vest): Add sanity tests for group validity
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 16, 2022
1 parent a1ff6ee commit a5db77c
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`group: base case Group validity 1`] = `
Object {
"done": [Function],
"errorCount": 4,
"getErrors": [Function],
"getErrorsByGroup": [Function],
"getWarnings": [Function],
"getWarningsByGroup": [Function],
"groups": Object {
"group_1": Object {
"field_1": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 1,
"valid": true,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 1,
"errors": Array [],
"testCount": 2,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
},
"group_2": Object {
"field_1": Object {
"errorCount": 1,
"errors": Array [],
"testCount": 1,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 1,
"valid": true,
"warnCount": 0,
"warnings": Array [],
},
},
"group_3": Object {
"field_1": Object {
"errorCount": 1,
"errors": Array [],
"testCount": 1,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 1,
"errors": Array [],
"testCount": 1,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
},
"group_4": Object {
"field_1": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 1,
"valid": true,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 1,
"valid": true,
"warnCount": 0,
"warnings": Array [],
},
},
},
"hasErrors": [Function],
"hasErrorsByGroup": [Function],
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 9,
"tests": Object {
"field_1": Object {
"errorCount": 2,
"errors": Array [],
"testCount": 4,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 2,
"errors": Array [],
"testCount": 5,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
},
"valid": false,
"warnCount": 0,
}
`;
46 changes: 46 additions & 0 deletions packages/vest/src/core/isolate/isolates/__tests__/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,50 @@ describe('group: base case', () => {
expect(outsideGroup).not.toHaveProperty('groupName');
});
});

test('Group validity', () => {
const suite = vest.create(() => {
vest.group('group_1', () => {
vest.test('field_1', () => {});
vest.test('field_2', () => {});
vest.test('field_2', () => false);
});
vest.group('group_2', () => {
vest.test('field_1', () => false);
vest.test('field_2', () => {});
});
vest.group('group_3', () => {
vest.test('field_1', () => false);
vest.test('field_2', () => false);
});
vest.group('group_4', () => {
vest.test('field_1', () => {});
vest.test('field_2', () => {});
});
});

const res = suite();

expect(res.groups.group_1.field_1.valid).toBe(true);
expect(res.groups.group_1.field_2.valid).toBe(false);
expect(res.groups.group_2.field_1.valid).toBe(false);
expect(res.groups.group_2.field_2.valid).toBe(true);
expect(res.groups.group_3.field_1.valid).toBe(false);
expect(res.groups.group_3.field_2.valid).toBe(false);
expect(res.groups.group_4.field_1.valid).toBe(true);
expect(res.groups.group_4.field_2.valid).toBe(true);
expect(res.isValidByGroup('group_1')).toBe(false);
expect(res.isValidByGroup('group_1', 'field_1')).toBe(true);
expect(res.isValidByGroup('group_1', 'field_2')).toBe(false);
expect(res.isValidByGroup('group_2')).toBe(false);
expect(res.isValidByGroup('group_2', 'field_1')).toBe(false);
expect(res.isValidByGroup('group_2', 'field_2')).toBe(true);
expect(res.isValidByGroup('group_3')).toBe(false);
expect(res.isValidByGroup('group_3', 'field_1')).toBe(false);
expect(res.isValidByGroup('group_3', 'field_2')).toBe(false);
expect(res.isValidByGroup('group_4')).toBe(true);
expect(res.isValidByGroup('group_4', 'field_1')).toBe(true);
expect(res.isValidByGroup('group_4', 'field_2')).toBe(true);
expect(res).toMatchSnapshot();
});
});

1 comment on commit a5db77c

@vercel
Copy link

@vercel vercel bot commented on a5db77c May 16, 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-next-git-latest-ealush.vercel.app
vest-next.vercel.app
vest-website.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.