pest-testing by spatie/freek.dev
npx skills add https://github.com/spatie/freek.dev --skill pest-testing在以下情况时激活此技能:
使用 search-docs 获取详细的 Pest 4 模式和文档。
所有测试必须使用 Pest 编写。使用 php artisan make:test --pest {name}。
tests/Feature 和 tests/Unit 目录。tests/Browser/ 目录。it('is true', function () { expect(true)->toBeTrue(); });
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
php artisan test --compact --filter=testName。php artisan test --compact。php artisan test --compact tests/Feature/ExampleTest.php。使用特定的断言(assertSuccessful()、assertNotFound())而不是 assertStatus():
it('returns all', function () { $this->postJson('/api/docs', [])->assertSuccessful(); });
| 使用 | 替代 |
|---|---|
assertSuccessful() | assertStatus(200) |
assertNotFound() | assertStatus(404) |
assertForbidden() | assertStatus(403) |
在使用前导入模拟函数:use function Pest\Laravel\mock;
对重复性测试(验证规则等)使用数据集:
it('has emails', function (string $email) { expect($email)->not->toBeEmpty(); })->with([ 'james' => 'james@laravel.com', 'taylor' => 'taylor@laravel.com', ]);
| 功能 | 用途 |
|---|---|
| 浏览器测试 | 在真实浏览器中进行完整的集成测试 |
| 冒烟测试 | 快速验证多个页面 |
| 视觉回归 | 比较截图以检测视觉变化 |
| 测试分片 | 并行 CI 运行 |
| 架构测试 | 强制执行代码约定 |
浏览器测试在真实浏览器中运行,进行完整的集成测试:
tests/Browser/。Event::fake()、assertAuthenticated() 和模型工厂。RefreshDatabase 以获得干净状态。it('may reset the password', function () { Notification::fake();
$this->actingAs(User::factory()->create());
$page = visit('/sign-in');
$page->assertSee('Sign In')
->assertNoJavascriptErrors()
->click('Forgot Password?')
->fill('email', 'nuno@laravel.com')
->click('Send Reset Link')
->assertSee('We have emailed your password reset link!');
Notification::assertSent(ResetPassword::class);
});
快速验证多个页面没有 JavaScript 错误:
$pages = visit(['/', '/about', '/contact']);
$pages->assertNoJavascriptErrors()->assertNoConsoleLogs();
捕获并比较截图以检测视觉变化。
将测试拆分到并行进程中,以实现更快的 CI 运行。
Pest 4 包含架构测试(来自 Pest 3):
arch('controllers') ->expect('App\Http\Controllers') ->toExtendNothing() ->toHaveSuffix('Controller');
use function Pest\Laravel\mock;assertStatus(200) 而不是 assertSuccessful()assertNoJavascriptErrors()每周安装次数
117
代码仓库
GitHub 星标数
644
首次出现
2026年2月9日
安全审计
安装于
opencode113
codex112
gemini-cli111
github-copilot111
kimi-cli108
amp108
Activate this skill when:
Use search-docs for detailed Pest 4 patterns and documentation.
All tests must be written using Pest. Use php artisan make:test --pest {name}.
tests/Feature and tests/Unit directories.tests/Browser/ directory.it('is true', function () { expect(true)->toBeTrue(); });
php artisan test --compact --filter=testName.php artisan test --compact.php artisan test --compact tests/Feature/ExampleTest.php.Use specific assertions (assertSuccessful(), assertNotFound()) instead of assertStatus():
it('returns all', function () { $this->postJson('/api/docs', [])->assertSuccessful(); });
| Use | Instead of |
|---|---|
assertSuccessful() | assertStatus(200) |
assertNotFound() | assertStatus(404) |
assertForbidden() | assertStatus(403) |
Import mock function before use: use function Pest\Laravel\mock;
Use datasets for repetitive tests (validation rules, etc.):
it('has emails', function (string $email) { expect($email)->not->toBeEmpty(); })->with([ 'james' => 'james@laravel.com', 'taylor' => 'taylor@laravel.com', ]);
| Feature | Purpose |
|---|---|
| Browser Testing | Full integration tests in real browsers |
| Smoke Testing | Validate multiple pages quickly |
| Visual Regression | Compare screenshots for visual changes |
| Test Sharding | Parallel CI runs |
| Architecture Testing | Enforce code conventions |
Browser tests run in real browsers for full integration testing:
tests/Browser/.Event::fake(), assertAuthenticated(), and model factories.RefreshDatabase for clean state per test.it('may reset the password', function () { Notification::fake();
$this->actingAs(User::factory()->create());
$page = visit('/sign-in');
$page->assertSee('Sign In')
->assertNoJavascriptErrors()
->click('Forgot Password?')
->fill('email', 'nuno@laravel.com')
->click('Send Reset Link')
->assertSee('We have emailed your password reset link!');
Notification::assertSent(ResetPassword::class);
});
Quickly validate multiple pages have no JavaScript errors:
$pages = visit(['/', '/about', '/contact']);
$pages->assertNoJavascriptErrors()->assertNoConsoleLogs();
Capture and compare screenshots to detect visual changes.
Split tests across parallel processes for faster CI runs.
Pest 4 includes architecture testing (from Pest 3):
arch('controllers') ->expect('App\Http\Controllers') ->toExtendNothing() ->toHaveSuffix('Controller');
use function Pest\Laravel\mock; before using mockassertStatus(200) instead of assertSuccessful()assertNoJavascriptErrors() in browser testsWeekly Installs
117
Repository
GitHub Stars
644
First Seen
Feb 9, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode113
codex112
gemini-cli111
github-copilot111
kimi-cli108
amp108
测试策略完整指南:单元/集成/E2E测试金字塔与自动化实践
11,200 周安装
二进制初步分析指南:使用ReVa工具快速识别恶意软件与逆向工程
69 周安装
PrivateInvestigator 道德人员查找工具 | 公开数据调查、反向搜索与背景研究
69 周安装
TorchTitan:PyTorch原生分布式大语言模型预训练平台,支持4D并行与H100 GPU加速
69 周安装
screenshot 截图技能:跨平台桌面截图工具,支持macOS/Linux权限管理与多模式捕获
69 周安装
tmux进程管理最佳实践:交互式Shell初始化、会话命名与生命周期管理
69 周安装
Git Rebase Sync:安全同步分支的Git变基工具,解决冲突与备份
69 周安装