diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 09da3317..991082b6 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -19,6 +19,7 @@ use Pest\Support\NullClosure; use Pest\Support\Str; use Pest\TestSuite; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\AssertionFailedError; /** * @internal @@ -57,6 +58,14 @@ final class TestCall $this->testSuite->beforeEach->get($this->filename)[0]($this); } + /** + * Asserts that the test fails with the given message. + */ + public function fails(?string $message = null): self + { + return $this->throws(AssertionFailedError::class, $message); + } + /** * Asserts that the test throws the given `$exceptionClass` when called. */ diff --git a/tests/Features/Fail.php b/tests/Features/Fail.php new file mode 100644 index 00000000..7f5c98aa --- /dev/null +++ b/tests/Features/Fail.php @@ -0,0 +1,11 @@ +fail(); +})->throws(AssertionFailedError::class); + +it('may fail with the given message', function () { + $this->fail('this is a failure'); +})->throws(AssertionFailedError::class, 'this is a failure'); diff --git a/tests/Features/Fails.php b/tests/Features/Fails.php new file mode 100644 index 00000000..3f7dcd16 --- /dev/null +++ b/tests/Features/Fails.php @@ -0,0 +1,11 @@ +fail(); +})->fails(); + +it('may fail with the given message', function () { + $this->fail('this is a failure'); +})->fails('this is a failure');