Skip to content

Commit

Permalink
Add AbortSignalTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Sep 24, 2023
1 parent 5350446 commit 21c11ab
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/vest/src/core/test/__tests__/asyncTests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as vest from 'vest';

describe('AsyncTests', () => {
describe('AbortSignal', () => {
it('Should pass abort signal to test functions', () => {
const testFnSync = jest.fn();
const testFnAsync = jest.fn().mockResolvedValue(undefined);
const suite = vest.create(() => {
vest.test('field_1', testFnSync);
vest.test('field_2', testFnAsync);
});
suite();

expect(testFnSync.mock.calls[0][0]).toBeInstanceOf(AbortSignal);
expect(testFnAsync.mock.calls[0][0]).toBeInstanceOf(AbortSignal);
});

describe('When test is not canceled', () => {
it('Should proceed without aborting the test', async () => {
const testFn = jest.fn().mockResolvedValue(undefined);
const suite = vest.create(() => {
vest.test('field_1', testFn);
});
suite();

await expect(testFn.mock.calls[0][0].aborted).toBe(false);
});
});

describe('When test is canceled', () => {
it('Should abort the test', async () => {
const testFn = jest.fn().mockResolvedValue(undefined);
const suite = vest.create(() => {
vest.test('field_1', testFn);
});
suite();
suite();

await expect(testFn.mock.calls[0][0].aborted).toBe(true);
await expect(testFn.mock.calls[1][0].aborted).toBe(false);
});
});

describe('Multiple async tests', () => {
it('Should abort only the canceled test', async () => {
const testFn1 = jest.fn().mockResolvedValue(undefined);
const testFn2 = jest.fn().mockResolvedValue(undefined);

const suite = vest.create((only?: string) => {
vest.only(only);

vest.test('field_1', testFn1);
vest.test('field_2', testFn2);
});

suite();
suite('field_1');

await expect(testFn1.mock.calls[0][0].aborted).toBe(true);
expect(testFn2.mock.calls[0][0].aborted).toBe(false);
});
});
});
});

0 comments on commit 21c11ab

Please sign in to comment.