Skip to content

Commit

Permalink
patch(vest): refresh tests after cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent fd049e8 commit 5bcc14a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/vest/src/core/suite/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import matchingFieldName from 'matchingFieldName';
import omitOptionalTests from 'omitOptionalTests';
import { IVestResult, produceFullResult } from 'produce';
import { produceDraft, TDraftResult } from 'produceDraft';
import removeTestFromState from 'removeTestFromState';
import { useTestObjects, usePrevTestObjects } from 'stateHooks';
import { initBus } from 'vestBus';

Expand Down Expand Up @@ -67,6 +68,7 @@ export default function create<T extends (...args: any[]) => void>(
asArray(testObjects).forEach(testObject => {
if (matchingFieldName(testObject, name)) {
testObject.cancel();
removeTestFromState(testObject);
}
});
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/core/test/VestTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import genId from 'genId';

import removeTestFromState from 'removeTestFromState';
import shouldUseErrorAsMessage from 'shouldUseErrorAsMessage';
import { useRefreshTestObjects } from 'stateHooks';

export default class VestTest {
fieldName: string;
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class VestTest {

cancel(): void {
this.setStatus(STATUS_CANCELED);
removeTestFromState(this);
useRefreshTestObjects();
}

omit(): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/vest/src/core/test/__tests__/VestTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('VestTest', () => {
});

describe('testObject.cancel', () => {
it('Should remove a testObject from the state', () => {
it('Should set the testObject to cancel', () => {
return new Promise<void>(done => {
let testObject: VestTest;
const suite = vest.create(() => {
Expand All @@ -86,8 +86,8 @@ describe('VestTest', () => {
testObject.cancel();
});
suite();
expect(suite.get().tests.f1).toBeUndefined();
expect(suite.get().tests.f2).toBeDefined();

expect(testObject.isCanceled()).toBe(true);
done();
});
});
Expand Down

0 comments on commit 5bcc14a

Please sign in to comment.