Skip to content

Commit dcf8b1c

Browse files
committed
docs: draft()
1 parent 0b41ac6 commit dcf8b1c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/draft.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# Accessing intermediate suite results
2+
23
In some cases, you want to conditionally run tests based on the results of other tests. For example, preventing validating a field over the server when you already know the field is invalid.
34

45
For this you can use `vest.draft()`. The `traft` function returns the intermediate [result object](./result) of the currently running suite.
56

67
**Limitations when using vest.draft()**
78

8-
- It is only possible to access intermediate test results for sync tests, and it is recommended to put all the async tests at the bottom of your suite so they have access to the result of all the sync tests.
9+
- It is only possible to access intermediate test results for sync tests, and it is recommended to put all the async tests at the bottom of your suite so they have access to the result of all the syenc tests.
910
- You may not call draft from outside a running suite. Doing that will result in a thrown error.
11+
- Each `draft()` call returns a copy of your suite result, and its result gets outdated between test calls. Do not try to save `draft` result in a variable for later use, instead, call `draft` whenever you need to use it.
1012

1113
In the following example, we're preventing the async validation from running over the username field in case it already has errors.
1214

1315
```js
1416
import vest, { test, enforce } from 'vest';
1517

1618
vest('NewUserForm', () => {
17-
test('username', 'Must be a string between 2 and 10 chars', () => {
18-
enforce(data.username).isString().longerThan(1).shorterThan(11);
19-
});
20-
21-
if (!vest.draft().hasErrors('username')) {
22-
// if `username` did not pass the previous test, the following test won't run
23-
test('username', 'username already exists', () => doesTheUserExist(username));
24-
}
19+
test('username', 'Must be a string between 2 and 10 chars', () => {
20+
enforce(data.username).isString().longerThan(1).shorterThan(11);
21+
});
22+
23+
if (!vest.draft().hasErrors('username')) {
24+
// if `username` did not pass the previous test, the following test won't run
25+
test('username', 'username already exists', () =>
26+
doesTheUserExist(username)
27+
);
28+
}
2529
});
2630
```

0 commit comments

Comments
 (0)