Skip to content

Commit

Permalink
tests(vest): Completely remove itWithContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 1, 2022
1 parent 47b07cd commit f28a1a6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 78 deletions.
113 changes: 66 additions & 47 deletions packages/vest/src/core/test/__tests__/VestTest.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import wait from 'wait';

import itWithContext from '../../../../testUtils/itWithContext';

import VestTest from 'VestTest';
import { useAllIncomplete, useTestObjects } from 'stateHooks';
import { useAllIncomplete } from 'stateHooks';
import * as vest from 'vest';

const fieldName = 'unicycle';
Expand Down Expand Up @@ -92,57 +90,78 @@ describe('VestTest', () => {
});
});

itWithContext('Should be removed from the list of incomplete tests', () => {
const [, setTestObjects] = useTestObjects();
setTestObjects(({ prev, current }) => ({
prev,
current: current.concat(testObject),
}));
testObject.setPending();
{
const allIncomplete = useAllIncomplete();

expect(allIncomplete).toEqual(expect.arrayContaining([testObject]));
}
testObject.cancel();
{
const allIncomplete = useAllIncomplete();
expect(allIncomplete).toEqual(expect.not.arrayContaining([testObject]));
}
it('Should be removed from the list of incomplete tests', () => {
const control = jest.fn();
vest.create(() => {
const testObject = vest.test('f1', async () => {
await wait(100);
});

expect(testObject.isPending()).toBe(true);
{
const allIncomplete = useAllIncomplete();

expect(allIncomplete).toEqual(expect.arrayContaining([testObject]));
}
testObject.cancel();
{
const allIncomplete = useAllIncomplete();
expect(allIncomplete).toEqual(
expect.not.arrayContaining([testObject])
);
}
control();
})();
expect(control).toHaveBeenCalledTimes(1);
});

describe('final statuses', () => {
let testObject, fn;
let control;
beforeEach(() => {
fn = jest.fn();
testObject = new VestTest('field', fn);
control = jest.fn();
});
itWithContext('keep status unchanged when `failed`', () => {
testObject.fail();
expect(testObject.isFailing()).toBe(true);
testObject.skip();
expect(testObject.isSkipped()).toBe(false);
expect(testObject.isFailing()).toBe(true);
testObject.cancel();
expect(testObject.isCanceled()).toBe(false);
expect(testObject.isFailing()).toBe(true);
testObject.setPending();
expect(testObject.isPending()).toBe(false);
expect(testObject.isFailing()).toBe(true);
it('keep status unchanged when `failed`', () => {
vest.create(() => {
// async so it is not a final status
const testObject = vest.test('f1', async () => {
await wait(100);
});
testObject.fail();
expect(testObject.isFailing()).toBe(true);
testObject.skip();
expect(testObject.isSkipped()).toBe(false);
expect(testObject.isFailing()).toBe(true);
testObject.cancel();
expect(testObject.isCanceled()).toBe(false);
expect(testObject.isFailing()).toBe(true);
testObject.setPending();
expect(testObject.isPending()).toBe(false);
expect(testObject.isFailing()).toBe(true);
control();
})();
expect(control).toHaveBeenCalledTimes(1);
});

itWithContext('keep status unchanged when `canceled`', () => {
testObject.setStatus('CANCELED');
expect(testObject.isCanceled()).toBe(true);
testObject.fail();
expect(testObject.isCanceled()).toBe(true);
expect(testObject.isFailing()).toBe(false);
testObject.skip();
expect(testObject.isSkipped()).toBe(false);
expect(testObject.isCanceled()).toBe(true);
testObject.setPending();
expect(testObject.isPending()).toBe(false);
expect(testObject.isCanceled()).toBe(true);
it('keep status unchanged when `canceled`', () => {
vest.create(() => {
// async so it is not a final status
const testObject = vest.test('f1', async () => {
await wait(100);
});
testObject.setStatus('CANCELED');
expect(testObject.isCanceled()).toBe(true);
testObject.fail();
expect(testObject.isCanceled()).toBe(true);
expect(testObject.isFailing()).toBe(false);
testObject.skip();
expect(testObject.isSkipped()).toBe(false);
expect(testObject.isCanceled()).toBe(true);
testObject.setPending();
expect(testObject.isPending()).toBe(false);
expect(testObject.isCanceled()).toBe(true);
control();
})();
expect(control).toHaveBeenCalledTimes(1);
});
});
});
Expand Down
23 changes: 0 additions & 23 deletions packages/vest/testUtils/itWithContext.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/vest/testUtils/testObjects.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import VestTest from 'VestTest';
import { useSetTests } from 'stateHooks';

export function emptyTestObjects(): void {
useSetTests(() => []);
}

export function setTestObjects(...args: VestTest[]): void {
useSetTests(() => [...args]);
}

export function addTestObject(addedTests: VestTest[] | VestTest): void {
useSetTests(tests => tests.concat(addedTests));
}

1 comment on commit f28a1a6

@vercel
Copy link

@vercel vercel bot commented on f28a1a6 Jun 1, 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.vercel.app
vest-next-ealush.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app

Please sign in to comment.