Skip to content

Commit 0e5adb6

Browse files
authored
Merge pull request #346 from Willem-Jaap/willem-jaap/file-level-only-docs
feat: add docs for file level only
2 parents 76540ca + 18df48b commit 0e5adb6

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

filtering-tests.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,42 @@ The `--retry` flag reorders your test suites by prioritizing the previously fail
100100
<a name="only"></a>
101101
### `only()`
102102

103-
If you want to run a specific test in your test suite, you can use the `only()` method.
103+
During development, you may want to focus on running specific tests while excluding all others. Pest provides two ways to do this: running only tests in a specific file, or running only a specific test within a file.
104104

105-
```bash
105+
#### Running Only Tests in a File
106+
107+
When working on a specific feature, you can mark all tests in a file to run exclusively by calling the `pest()->only()` function at the top of your test file:
108+
109+
```php
110+
<?php
111+
112+
pest()->only();
113+
114+
test('first test', function () {
115+
// This will run
116+
});
117+
118+
test('second test', function () {
119+
// This will also run
120+
});
121+
```
122+
123+
All tests in files with `pest()->only()` will run, while tests in other files will be skipped.
124+
125+
#### Running a Single Test
126+
127+
To run only a specific test within a file, chain the `->only()` method to the test:
128+
129+
```php
106130
test('sum', function () {
107131
$result = sum(1, 2);
108132

109133
expect($result)->toBe(3);
110134
})->only();
135+
136+
test('another test', function () {
137+
// This will be skipped
138+
});
111139
```
112140

113141
---

0 commit comments

Comments
 (0)