Skip to content

Commit

Permalink
Add abort reason and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Sep 24, 2023
1 parent 5f9e3a8 commit 6088228
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/vest/src/core/isolate/IsolateTest/VestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class VestTest {

static cancel(test: TIsolateTest): void {
VestTest.setStatus(test, TestStatus.CANCELED);
VestTest.getData(test).abortController.abort();
VestTest.getData(test).abortController.abort(TestStatus.CANCELED);
}

static omit(test: TIsolateTest): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ describe('Test Function Payload', () => {
await expect(callPayload(testFn).signal.aborted).toBe(true);
await expect(callPayload(testFn, 1, 0).signal.aborted).toBe(false);
});

it('Should set the reason to `canceled`', async () => {
const testFn = jest.fn().mockResolvedValue(undefined);
const suite = vest.create(() => {
vest.test('field_1', testFn);
});
suite();
suite();

await expect(callPayload(testFn).signal.reason).toBe('CANCELED');
});
});

describe('Multiple async tests', () => {
Expand Down
10 changes: 6 additions & 4 deletions website/docs/writing_tests/async_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ test('name', 'Already Taken', async () => {

> Since 5.1.0
Each Vest test is passed as an argument an `AbortSignal` object. Vest internally sets the AbortSignal `aborted` property to true when the test is canceled.
Each test function is passed an object with a `signal` property. This signal is an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which can be used to terminate your async operations once a test is canceled.

A test is canceled when running the same test again before its previous run has completed.
The AbortSignal has a boolean `aborted` property, by which you can determine whether the test was canceled or not.

A test gets canceled when running the same test again before its previous run has completed.

You can use the AbortSignal to stop the execution of your async test, or pass it to your fetch request.

[Read more on AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
[More on AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).

```js
test('name', 'Already Taken', async signal => {
test('name', 'Already Taken', async ({ signal }) => {
// ...
});
```

0 comments on commit 6088228

Please sign in to comment.