Skip to content

Commit 8597af2

Browse files
committed
patch(vest): Call done callback immediately when field does not exist
1 parent d21fa81 commit 8597af2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/vest/src/core/suite/produce/__tests__/done.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,18 @@ describe('done', () => {
316316
expect(done_0).not.toHaveBeenCalled();
317317
});
318318
});
319+
320+
describe('Passing a field that does not exist', () => {
321+
it('Should call the callback immedaitely', () => {
322+
const cb = jest.fn();
323+
324+
const suite = vest.create(() => {
325+
vest.test('test', () => {});
326+
});
327+
328+
suite().done('non-existent', cb);
329+
330+
expect(cb).toHaveBeenCalled();
331+
});
332+
});
319333
});

packages/vest/src/core/suite/produce/produceSuiteRunResult.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { isEmpty, assign, isFunction, cache as createCache } from 'vest-utils';
1+
import {
2+
assign,
3+
isFunction,
4+
cache as createCache,
5+
numberEquals,
6+
} from 'vest-utils';
27

38
import ctx from 'ctx';
49
import hasRemainingTests from 'hasRemainingTests';
@@ -33,8 +38,7 @@ function shouldSkipDoneRegistration(
3338
// If we do not have any test runs for the current field
3439
return !!(
3540
!isFunction(callback) ||
36-
(fieldName &&
37-
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount)))
41+
(fieldName && numberEquals(output.tests[fieldName]?.testCount, 0))
3842
);
3943
}
4044

0 commit comments

Comments
 (0)