vest 5.0.0-dev-781e21 → 5.0.2-dev-d315d9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +2 -57
- package/dist/cjs/classnames.development.js +18 -16
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +20 -83
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +19 -82
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +12 -9
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +4 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1287 -1153
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +20 -18
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -58
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -90
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -88
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +12 -9
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +5 -9
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1286 -1148
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +21 -19
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -57
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +32 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +32 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +16 -13
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +7 -11
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1289 -1155
- package/dist/umd/vest.production.js +1 -1
- package/package.json +12 -16
- package/src/__tests__/__snapshots__/integration.async-tests.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.base.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +243 -0
- package/src/__tests__/__snapshots__/integration.stateful-tests.test.ts.snap +376 -0
- package/src/__tests__/integration.async-tests.test.ts +90 -0
- package/src/__tests__/integration.base.test.ts +45 -0
- package/src/__tests__/integration.exclusive.test.ts +88 -0
- package/src/__tests__/integration.stateful-async.test.ts +137 -0
- package/src/__tests__/integration.stateful-tests.test.ts +155 -0
- package/src/__tests__/isolate.test.ts +288 -0
- package/src/__tests__/state_refill.test.ts +41 -0
- package/src/core/SuiteWalker/SuiteWalker.ts +64 -0
- package/src/core/SuiteWalker/__tests__/hasRemainingTests.test.ts +130 -0
- package/src/core/VestBus/VestBus.ts +78 -0
- package/src/core/context/PersistedContext.ts +243 -0
- package/src/core/context/SuiteContext.ts +74 -0
- package/src/core/isolate/IsolateTest/IsolateTest.ts +213 -0
- package/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +156 -0
- package/src/core/isolate/IsolateTest/IsolateTestStateMachine.ts +69 -0
- package/src/core/isolate/IsolateTest/SimpleStateMachine.ts +43 -0
- package/src/core/isolate/IsolateTest/TestWalker.ts +77 -0
- package/src/core/isolate/IsolateTypes.ts +10 -0
- package/src/core/isolate/isIsolate.ts +6 -0
- package/src/core/isolate/isolate.ts +110 -0
- package/src/core/isolate/reconciler/Reconciler/Reconciler.ts +123 -0
- package/src/core/isolate/reconciler/cancelOverriddenPendingTest.ts +15 -0
- package/src/core/isolate/reconciler/isSameProfileTest.ts +12 -0
- package/src/core/isolate/walker.ts +127 -0
- package/src/core/test/TestTypes.ts +3 -0
- package/src/core/test/__tests__/IsolateTest.test.ts +152 -0
- package/src/core/test/__tests__/__snapshots__/IsolateTest.test.ts.snap +39 -0
- package/src/core/test/__tests__/__snapshots__/memo.test.ts.snap +101 -0
- package/src/core/test/__tests__/__snapshots__/test.test.ts.snap +231 -0
- package/src/core/test/__tests__/key.test.ts +195 -0
- package/src/core/test/__tests__/memo.test.ts +218 -0
- package/src/core/test/__tests__/merging_of_previous_test_runs.test.ts +341 -0
- package/src/core/test/__tests__/runAsyncTest.test.ts +175 -0
- package/src/core/test/__tests__/test.test.ts +226 -0
- package/src/core/test/helpers/__tests__/nonMatchingSeverityProfile.test.ts +52 -0
- package/src/core/test/helpers/asVestTest.ts +9 -0
- package/src/core/test/helpers/matchingFieldName.ts +16 -0
- package/src/core/test/helpers/matchingGroupName.ts +12 -0
- package/src/core/test/helpers/nonMatchingSeverityProfile.ts +14 -0
- package/src/core/test/helpers/shouldUseErrorMessage.ts +9 -0
- package/src/core/test/test.memo.ts +81 -0
- package/src/core/test/test.ts +64 -0
- package/src/core/test/testLevelFlowControl/runTest.ts +86 -0
- package/src/core/test/testLevelFlowControl/verifyTestRun.ts +32 -0
- package/src/core/test/testObjectIsolate.ts +11 -0
- package/src/errors/ErrorStrings.ts +4 -0
- package/src/exports/__tests__/classnames.test.ts +92 -0
- package/src/exports/__tests__/parser.test.ts +441 -0
- package/src/exports/__tests__/promisify.test.ts +77 -0
- package/src/exports/classnames.ts +35 -0
- package/src/exports/enforce@compose.ts +1 -0
- package/src/exports/enforce@compounds.ts +1 -0
- package/src/exports/enforce@schema.ts +1 -0
- package/src/exports/parser.ts +63 -0
- package/src/exports/promisify.ts +18 -0
- package/src/hooks/__tests__/__snapshots__/include.test.ts.snap +794 -0
- package/src/hooks/__tests__/eager.test.ts +130 -0
- package/src/hooks/__tests__/exclusive.test.ts +578 -0
- package/src/hooks/__tests__/include.test.ts +431 -0
- package/src/hooks/__tests__/optional.test.ts +83 -0
- package/src/hooks/__tests__/warn.test.ts +42 -0
- package/src/hooks/exclusive.ts +179 -0
- package/src/hooks/include.ts +54 -0
- package/src/hooks/mode.ts +47 -0
- package/src/hooks/optional/OptionalTypes.ts +31 -0
- package/src/hooks/optional/optional.ts +69 -0
- package/src/hooks/warn.ts +19 -0
- package/src/isolates/__tests__/__snapshots__/each.test.ts.snap +3 -0
- package/src/isolates/__tests__/__snapshots__/group.test.ts.snap +114 -0
- package/src/isolates/__tests__/__snapshots__/omitWhen.test.ts.snap +443 -0
- package/src/isolates/__tests__/__snapshots__/skipWhen.test.ts.snap +99 -0
- package/src/isolates/__tests__/each.test.ts +35 -0
- package/src/isolates/__tests__/group.test.ts +362 -0
- package/src/isolates/__tests__/omitWhen.test.ts +246 -0
- package/src/isolates/__tests__/skipWhen.test.ts +163 -0
- package/src/isolates/each.ts +30 -0
- package/src/isolates/group.ts +9 -0
- package/src/isolates/omitWhen.ts +41 -0
- package/src/isolates/skipWhen.ts +42 -0
- package/src/suite/__tests__/__snapshots__/create.test.ts.snap +67 -0
- package/src/suite/__tests__/create.test.ts +109 -0
- package/src/suite/__tests__/remove.test.ts +50 -0
- package/src/suite/__tests__/resetField.test.ts +74 -0
- package/src/suite/createSuite.ts +94 -0
- package/src/suite/runCallbacks.ts +28 -0
- package/src/suiteResult/Severity.ts +15 -0
- package/src/suiteResult/SuiteResultTypes.ts +42 -0
- package/src/suiteResult/__tests__/done.test.ts +334 -0
- package/src/suiteResult/__tests__/produce.test.ts +163 -0
- package/src/suiteResult/done/deferDoneCallback.ts +28 -0
- package/src/suiteResult/done/shouldSkipDoneRegistration.ts +20 -0
- package/src/suiteResult/selectors/__tests__/__snapshots__/collectFailureMessages.test.ts.snap +89 -0
- package/src/suiteResult/selectors/__tests__/collectFailureMessages.test.ts +124 -0
- package/src/suiteResult/selectors/__tests__/getFailures.test.ts +158 -0
- package/src/suiteResult/selectors/__tests__/getFailuresByGroup.test.ts +199 -0
- package/src/suiteResult/selectors/__tests__/hasFailures.test.ts +141 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByGroup.test.ts +185 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByTestObject.test.ts +88 -0
- package/src/suiteResult/selectors/__tests__/isValid.test.ts +359 -0
- package/src/suiteResult/selectors/__tests__/isValidByGroup.test.ts +480 -0
- package/src/suiteResult/selectors/collectFailures.ts +43 -0
- package/src/suiteResult/selectors/hasFailuresByTestObjects.ts +62 -0
- package/src/suiteResult/selectors/produceSuiteSummary.ts +135 -0
- package/src/suiteResult/selectors/shouldAddValidProperty.ts +148 -0
- package/src/suiteResult/selectors/suiteSelectors.ts +199 -0
- package/src/suiteResult/suiteResult.ts +15 -0
- package/src/suiteResult/suiteRunResult.ts +43 -0
- package/src/vest.ts +36 -0
- package/testUtils/TVestMock.ts +5 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +2 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/tsconfig.json +84 -2
- package/types/classnames.d.ts +39 -4
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce/compose.d.ts +2 -126
- package/types/enforce/compose.d.ts.map +1 -0
- package/types/enforce/compounds.d.ts +2 -136
- package/types/enforce/compounds.d.ts.map +1 -0
- package/types/enforce/schema.d.ts +2 -144
- package/types/enforce/schema.d.ts.map +1 -0
- package/types/parser.d.ts +45 -10
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +36 -34
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +169 -224
- package/types/vest.d.ts.map +1 -0
- package/CHANGELOG.md +0 -87
- package/testUtils/expandStateRef.ts +0 -8
- package/testUtils/runCreateRef.ts +0 -10
- package/testUtils/testObjects.ts +0 -6
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import * as vest from 'vest';
|
|
2
|
+
|
|
3
|
+
describe('include', () => {
|
|
4
|
+
let cb1 = jest.fn(),
|
|
5
|
+
cb2 = jest.fn();
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
cb1 = jest.fn(() => false);
|
|
9
|
+
cb2 = jest.fn(() => false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('When not passing a string fieldName', () => {
|
|
13
|
+
it('Should throw an error', () => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
expect(() => vest.include({})).toThrow();
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
expect(() => vest.include(undefined)).toThrow();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('There is an `onlyd` field', () => {
|
|
22
|
+
describe('`include` is run as-is without modifiers', () => {
|
|
23
|
+
it('Should run the included test along with the onlyd test', () => {
|
|
24
|
+
const suite = vest.create(() => {
|
|
25
|
+
vest.only('field_1');
|
|
26
|
+
vest.include('field_2');
|
|
27
|
+
|
|
28
|
+
vest.test('field_1', () => false);
|
|
29
|
+
vest.test('field_2', () => false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const res = suite();
|
|
33
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
34
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
35
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
36
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
37
|
+
expect(res).toMatchSnapshot();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('include().when()', () => {
|
|
42
|
+
describe('`when` param is a string', () => {
|
|
43
|
+
describe('`when` param is a name of an onlyd field', () => {
|
|
44
|
+
it('Should run included field along with the onlyd field', () => {
|
|
45
|
+
const suite = vest.create(() => {
|
|
46
|
+
vest.only('field_1');
|
|
47
|
+
vest.include('field_2').when('field_1');
|
|
48
|
+
|
|
49
|
+
vest.test('field_1', () => false);
|
|
50
|
+
vest.test('field_2', () => false);
|
|
51
|
+
vest.test('field_3', () => false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const res = suite();
|
|
55
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
56
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
57
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
58
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
59
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
60
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
61
|
+
expect(res).toMatchSnapshot();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('`when` param is a name of a non-included field', () => {
|
|
65
|
+
it('Should avoid running the included field', () => {
|
|
66
|
+
const suite = vest.create(() => {
|
|
67
|
+
vest.only('field_1');
|
|
68
|
+
vest.include('field_2').when('field_3');
|
|
69
|
+
|
|
70
|
+
vest.test('field_1', () => false);
|
|
71
|
+
vest.test('field_2', () => false);
|
|
72
|
+
vest.test('field_3', () => false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const res = suite();
|
|
76
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
77
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
78
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
79
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
80
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
81
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
82
|
+
expect(res).toMatchSnapshot();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('`when` param is a name of a skipped field', () => {
|
|
86
|
+
it('Should avoid running the included field', () => {
|
|
87
|
+
const suite = vest.create(() => {
|
|
88
|
+
vest.only('field_1');
|
|
89
|
+
vest.skip('field_3');
|
|
90
|
+
vest.include('field_2').when('field_3');
|
|
91
|
+
|
|
92
|
+
vest.test('field_1', () => false);
|
|
93
|
+
vest.test('field_2', () => false);
|
|
94
|
+
vest.test('field_3', () => false);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const res = suite();
|
|
98
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
99
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
100
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
101
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
102
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
103
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
104
|
+
expect(res).toMatchSnapshot();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe('`when` param is a boolean', () => {
|
|
109
|
+
describe('when `true`', () => {
|
|
110
|
+
it('Should run included field', () => {
|
|
111
|
+
const suite = vest.create(() => {
|
|
112
|
+
vest.only('field_1');
|
|
113
|
+
vest.include('field_2').when(true);
|
|
114
|
+
|
|
115
|
+
vest.test('field_1', () => false);
|
|
116
|
+
vest.test('field_2', () => false);
|
|
117
|
+
vest.test('field_3', () => false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const res = suite();
|
|
121
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
122
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
123
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
124
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
125
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
126
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
127
|
+
expect(res).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('when `false`', () => {
|
|
131
|
+
it('Should skip run included field', () => {
|
|
132
|
+
const suite = vest.create(() => {
|
|
133
|
+
vest.only('field_1');
|
|
134
|
+
vest.include('field_2').when(false);
|
|
135
|
+
|
|
136
|
+
vest.test('field_1', () => false);
|
|
137
|
+
vest.test('field_2', () => false);
|
|
138
|
+
vest.test('field_3', () => false);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const res = suite();
|
|
142
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
143
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
144
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
145
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
146
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
147
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
148
|
+
expect(res).toMatchSnapshot();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('`when` param is a function', () => {
|
|
153
|
+
describe('when returning `true`', () => {
|
|
154
|
+
it('Should run included field', () => {
|
|
155
|
+
const suite = vest.create(() => {
|
|
156
|
+
vest.only('field_1');
|
|
157
|
+
vest.include('field_2').when(() => true);
|
|
158
|
+
|
|
159
|
+
vest.test('field_1', () => false);
|
|
160
|
+
vest.test('field_2', () => false);
|
|
161
|
+
vest.test('field_3', () => false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const res = suite();
|
|
165
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
166
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
167
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
168
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
169
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
170
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
171
|
+
expect(res).toMatchSnapshot();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe('when returning`false`', () => {
|
|
175
|
+
it('Should skip run included field', () => {
|
|
176
|
+
const suite = vest.create(() => {
|
|
177
|
+
vest.only('field_1');
|
|
178
|
+
vest.include('field_2').when(() => false);
|
|
179
|
+
|
|
180
|
+
vest.test('field_1', () => false);
|
|
181
|
+
vest.test('field_2', () => false);
|
|
182
|
+
vest.test('field_3', () => false);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const res = suite();
|
|
186
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
187
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
188
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
189
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
190
|
+
expect(res.hasErrors('field_3')).toBe(false);
|
|
191
|
+
expect(res.tests.field_3.testCount).toBe(0);
|
|
192
|
+
expect(res).toMatchSnapshot();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('Callback evaluation', () => {
|
|
197
|
+
it('Should run the callback for each matching test', () => {
|
|
198
|
+
const cb = jest.fn(() => true);
|
|
199
|
+
const suite = vest.create(() => {
|
|
200
|
+
vest.only('field_1');
|
|
201
|
+
vest.include('field_2').when(cb);
|
|
202
|
+
|
|
203
|
+
vest.test('field_1', () => false);
|
|
204
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
205
|
+
vest.test('field_2', () => false);
|
|
206
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
207
|
+
vest.test('field_3', () => false);
|
|
208
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
209
|
+
vest.test('field_2', () => false);
|
|
210
|
+
expect(cb).toHaveBeenCalledTimes(2);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
suite();
|
|
214
|
+
expect(cb).toHaveBeenCalledTimes(2);
|
|
215
|
+
});
|
|
216
|
+
it('Should evaluate per test run', () => {
|
|
217
|
+
const cb1 = jest.fn(() => false);
|
|
218
|
+
const cb2 = jest.fn(() => false);
|
|
219
|
+
const cb3 = jest.fn(() => false);
|
|
220
|
+
const cb4 = jest.fn(() => false);
|
|
221
|
+
|
|
222
|
+
const suite = vest.create(() => {
|
|
223
|
+
let shouldRun = false;
|
|
224
|
+
vest.only('x');
|
|
225
|
+
vest.include('field_1').when(() => shouldRun);
|
|
226
|
+
|
|
227
|
+
vest.test('field_1', cb1);
|
|
228
|
+
shouldRun = true;
|
|
229
|
+
vest.test('field_1', cb2);
|
|
230
|
+
shouldRun = false;
|
|
231
|
+
vest.test('field_1', cb3);
|
|
232
|
+
shouldRun = true;
|
|
233
|
+
vest.test('field_1', cb4);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const res = suite();
|
|
237
|
+
expect(cb1).toHaveBeenCalledTimes(0);
|
|
238
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
239
|
+
expect(cb3).toHaveBeenCalledTimes(0);
|
|
240
|
+
expect(cb4).toHaveBeenCalledTimes(1);
|
|
241
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
242
|
+
expect(res.tests.field_1.testCount).toBe(2);
|
|
243
|
+
expect(res).toMatchSnapshot();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('Field is excluded via `skip`', () => {
|
|
251
|
+
it('Should disregard `include` and avoid running the test', () => {
|
|
252
|
+
const suite = vest.create(() => {
|
|
253
|
+
vest.skip('field_1');
|
|
254
|
+
vest.include('field_1');
|
|
255
|
+
|
|
256
|
+
vest.test('field_1', () => false);
|
|
257
|
+
vest.test('field_2', () => false);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const res = suite();
|
|
261
|
+
expect(res.hasErrors('field_1')).toBe(false);
|
|
262
|
+
expect(res.tests.field_1.testCount).toBe(0);
|
|
263
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
264
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
265
|
+
expect(res).toMatchSnapshot();
|
|
266
|
+
});
|
|
267
|
+
it('Should disregard `include.when` and avoid running the test', () => {
|
|
268
|
+
const suite = vest.create(() => {
|
|
269
|
+
vest.skip('field_1');
|
|
270
|
+
vest.include('field_1').when(true);
|
|
271
|
+
|
|
272
|
+
vest.test('field_1', () => false);
|
|
273
|
+
vest.test('field_2', () => false);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const res = suite();
|
|
277
|
+
expect(res.hasErrors('field_1')).toBe(false);
|
|
278
|
+
expect(res.tests.field_1.testCount).toBe(0);
|
|
279
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
280
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
281
|
+
expect(res).toMatchSnapshot();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('Field is included via `only`', () => {
|
|
286
|
+
it('Should disregard `when` condition and test the field anyway', () => {
|
|
287
|
+
const suite = vest.create(() => {
|
|
288
|
+
vest.only('field_1');
|
|
289
|
+
vest.include('field_1').when(false);
|
|
290
|
+
|
|
291
|
+
vest.test('field_1', () => false);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const res = suite();
|
|
295
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
296
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe('Test is excluded by being out of an included group', () => {
|
|
300
|
+
it('Should disregard `include` and avoid running the test', () => {
|
|
301
|
+
const suite = vest.create(() => {
|
|
302
|
+
vest.only.group('g1');
|
|
303
|
+
vest.include('field_1');
|
|
304
|
+
vest.group('g1', () => {});
|
|
305
|
+
|
|
306
|
+
vest.test('field_1', () => false);
|
|
307
|
+
vest.group('g2', () => {
|
|
308
|
+
vest.test('field_1', () => false);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const res = suite();
|
|
313
|
+
expect(res.hasErrors('field_1')).toBe(false);
|
|
314
|
+
expect(res.tests.field_1.testCount).toBe(0);
|
|
315
|
+
expect(res).toMatchSnapshot();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe('Test is excluded via `skip.group`', () => {
|
|
319
|
+
it('Should disregard `include` and avoid running the test', () => {
|
|
320
|
+
const suite = vest.create(() => {
|
|
321
|
+
vest.skip.group('g1');
|
|
322
|
+
vest.include('field_1');
|
|
323
|
+
|
|
324
|
+
vest.group('g1', () => {
|
|
325
|
+
vest.test('field_1', cb1);
|
|
326
|
+
vest.test('field_2', () => false);
|
|
327
|
+
});
|
|
328
|
+
vest.test('field_1', cb2);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const res = suite();
|
|
332
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
333
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
334
|
+
expect(cb1).toHaveBeenCalledTimes(0);
|
|
335
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
336
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
337
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
338
|
+
expect(res).toMatchSnapshot();
|
|
339
|
+
});
|
|
340
|
+
it('Should disregard `include.when` and avoid running the test', () => {
|
|
341
|
+
const suite = vest.create(() => {
|
|
342
|
+
vest.skip.group('g1');
|
|
343
|
+
vest.include('field_1').when(true);
|
|
344
|
+
|
|
345
|
+
vest.group('g1', () => {
|
|
346
|
+
vest.test('field_1', cb1);
|
|
347
|
+
vest.test('field_2', () => false);
|
|
348
|
+
});
|
|
349
|
+
vest.test('field_1', cb2);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const res = suite();
|
|
353
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
354
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
355
|
+
expect(cb1).toHaveBeenCalledTimes(0);
|
|
356
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
357
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
358
|
+
expect(res.tests.field_2.testCount).toBe(0);
|
|
359
|
+
expect(res).toMatchSnapshot();
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
describe('Test is excluded via `skipWhen`', () => {
|
|
363
|
+
it('Should disregard `include` and avoid running the matching tests', () => {
|
|
364
|
+
const suite = vest.create(() => {
|
|
365
|
+
vest.include('field_1');
|
|
366
|
+
|
|
367
|
+
vest.skipWhen(true, () => {
|
|
368
|
+
vest.test('field_1', cb1);
|
|
369
|
+
});
|
|
370
|
+
vest.test('field_1', cb2);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const res = suite();
|
|
374
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
375
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
376
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
377
|
+
expect(cb2).toHaveBeenCalled();
|
|
378
|
+
expect(res).toMatchSnapshot();
|
|
379
|
+
});
|
|
380
|
+
it('Should disregard `include.when` and avoid running the matching tests', () => {
|
|
381
|
+
const suite = vest.create(() => {
|
|
382
|
+
vest.include('field_1').when(true);
|
|
383
|
+
|
|
384
|
+
vest.skipWhen(true, () => {
|
|
385
|
+
vest.test('field_1', cb1);
|
|
386
|
+
});
|
|
387
|
+
vest.test('field_1', cb2);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const res = suite();
|
|
391
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
392
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
393
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
394
|
+
expect(cb2).toHaveBeenCalled();
|
|
395
|
+
expect(res).toMatchSnapshot();
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
describe('When no `skip` or `only`', () => {
|
|
399
|
+
test('include has no effect', () => {
|
|
400
|
+
const suite = vest.create(() => {
|
|
401
|
+
vest.include('field_1');
|
|
402
|
+
|
|
403
|
+
vest.test('field_1', () => false);
|
|
404
|
+
vest.test('field_2', () => false);
|
|
405
|
+
});
|
|
406
|
+
const res = suite();
|
|
407
|
+
|
|
408
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
409
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
410
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
411
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
412
|
+
expect(res).toMatchSnapshot();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test('include().when has no effect', () => {
|
|
416
|
+
const suite = vest.create(() => {
|
|
417
|
+
vest.include('field_1').when(false);
|
|
418
|
+
|
|
419
|
+
vest.test('field_1', () => false);
|
|
420
|
+
vest.test('field_2', () => false);
|
|
421
|
+
});
|
|
422
|
+
const res = suite();
|
|
423
|
+
|
|
424
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
425
|
+
expect(res.tests.field_1.testCount).toBe(1);
|
|
426
|
+
expect(res.hasErrors('field_2')).toBe(true);
|
|
427
|
+
expect(res.tests.field_2.testCount).toBe(1);
|
|
428
|
+
expect(res).toMatchSnapshot();
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { optional, create, test } from 'vest';
|
|
2
|
+
|
|
3
|
+
describe('optional hook', () => {
|
|
4
|
+
describe('Functional Optional Interface', () => {
|
|
5
|
+
it('Should omit test failures based on optional functions', () => {
|
|
6
|
+
const suite = create(() => {
|
|
7
|
+
optional({
|
|
8
|
+
f1: () => true,
|
|
9
|
+
f2: () => true,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('f1', () => false);
|
|
13
|
+
test('f2', () => false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const res = suite();
|
|
17
|
+
|
|
18
|
+
expect(res.hasErrors('f1')).toBe(false);
|
|
19
|
+
expect(res.hasErrors('f2')).toBe(false);
|
|
20
|
+
expect(res.isValid('f1')).toBe(true);
|
|
21
|
+
expect(res.isValid('f2')).toBe(true);
|
|
22
|
+
expect(res.isValid()).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('example: "any of" test', () => {
|
|
26
|
+
it('Should allow specifying custom optional based on other tests in the suite', () => {
|
|
27
|
+
const suite = create(() => {
|
|
28
|
+
optional({
|
|
29
|
+
f1: () => !suite.get().hasErrors('f2'),
|
|
30
|
+
f2: () => !suite.get().hasErrors('f1'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('f1', () => false);
|
|
34
|
+
test('f2', () => true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const res = suite();
|
|
38
|
+
|
|
39
|
+
expect(res.hasErrors('f1')).toBe(false);
|
|
40
|
+
expect(res.hasErrors('f2')).toBe(false);
|
|
41
|
+
expect(res.isValid('f1')).toBe(true);
|
|
42
|
+
expect(res.isValid('f2')).toBe(true);
|
|
43
|
+
expect(res.isValid()).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('boolean optional field indicator', () => {
|
|
49
|
+
describe('When true', () => {
|
|
50
|
+
it('Should omit field as optional', () => {
|
|
51
|
+
const suite = create(() => {
|
|
52
|
+
optional({
|
|
53
|
+
field_1: true,
|
|
54
|
+
});
|
|
55
|
+
test('field_1', () => false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const res = suite();
|
|
59
|
+
|
|
60
|
+
expect(res.hasErrors('field_1')).toBe(false);
|
|
61
|
+
expect(res.isValid('field_1')).toBe(true);
|
|
62
|
+
expect(res.isValid()).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('When false', () => {
|
|
67
|
+
it('Should fail the field normally', () => {
|
|
68
|
+
const suite = create(() => {
|
|
69
|
+
optional({
|
|
70
|
+
field_1: false,
|
|
71
|
+
});
|
|
72
|
+
test('field_1', () => false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const res = suite();
|
|
76
|
+
|
|
77
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
78
|
+
expect(res.isValid('field_1')).toBe(false);
|
|
79
|
+
expect(res.isValid()).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
|
|
3
|
+
import { ErrorStrings } from 'ErrorStrings';
|
|
4
|
+
import * as vest from 'vest';
|
|
5
|
+
|
|
6
|
+
const { create, test, warn } = vest;
|
|
7
|
+
|
|
8
|
+
function asVestTest(t: unknown): vest.IsolateTest {
|
|
9
|
+
return t as vest.IsolateTest;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('warn hook', () => {
|
|
13
|
+
describe('When currentTest exists', () => {
|
|
14
|
+
it('Should set warns to true', () => {
|
|
15
|
+
let t;
|
|
16
|
+
create(() => {
|
|
17
|
+
t = test(faker.lorem.word(), faker.lorem.sentence(), () => {
|
|
18
|
+
warn();
|
|
19
|
+
});
|
|
20
|
+
})();
|
|
21
|
+
|
|
22
|
+
expect(asVestTest(t).warns()).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('Error handling', () => {
|
|
27
|
+
it('Should throw error when currentTest is not present', () => {
|
|
28
|
+
const done = jest.fn();
|
|
29
|
+
create(() => {
|
|
30
|
+
expect(warn).toThrow(
|
|
31
|
+
"warn hook called outside of a test callback. It won't have an effect."
|
|
32
|
+
);
|
|
33
|
+
done();
|
|
34
|
+
})();
|
|
35
|
+
expect(done).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should throw error when no suite present', () => {
|
|
39
|
+
expect(warn).toThrow(ErrorStrings.HOOK_CALLED_OUTSIDE);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|