mirror of
https://github.com/pestphp/pest.git
synced 2026-03-08 08:47:22 +01:00
add custom message to failed expectations
This commit is contained in:
@ -24,10 +24,18 @@ test('failures', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('foo');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'foo'");
|
||||
|
||||
test('failures with custom message', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('foo', message: 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with nested key', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('d.bar');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'd.bar'");
|
||||
|
||||
test('failures with nested key and custom message', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('d.bar', message: 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with plain key with dots', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('missing.key.with.dots');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'missing.key.with.dots'");
|
||||
|
||||
Reference in New Issue
Block a user