theant72 wrote a comment+100 XP
1mo ago
I wrote the test like you:
use Livewire\Livewire; use App\Models\Post; use function Pest\Laravel\assertDatabaseHas; use function Pest\Laravel\assertDatabaseMissing;
test('testing post creation', function () {
assertDatabaseMissing(Post::class, [
'title', 'Test title',
'content', 'Test content'
]);
visit('/post/create')
->debug()
->type('[wire\:model="title"]', 'Test title')
->type('[wire\:model="content"]', 'Test content')
->press('Save')
->assertPathIs('/');
assertDatabaseHas(Post::class, [
'title', 'Test title',
'content', 'Test content'
]);
});
but everytime I run the browser test, I got this error that doesn't appera in Unit Testing
FAIL Tests\Feature\CreatePostTest
⨯ testing post creation 116.78s
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
FAILED Tests\Feature\CreatePostTest > testing post creation
Failed asserting that a row in the table [posts] matches the attributes [
"title",
"Test title",
"content",
"Test content"
].
Found: [ { ""0"": "0", ""1"": "1", ""2"": "2", ""3"": "3" } ].
at tests/Feature/CreatePostTest.php:30 26▕ ->type('[wire:model="content"]', 'Test content') 27▕ ->press('Create') 28▕ ->assertPathIs('/'); 29▕ ➜ 30▕ assertDatabaseHas(Post::class, [ 31▕ 'title', 'Test title', 32▕ 'content', 'Test content' 33▕ ]); 34▕ });
Tests: 1 failed (3 assertions) Duration: 120.15s
It doesn't write in the database ... why ?