Hi , im learning livewire so just write this test :
/**
* @test
*/
public function if_a_wrong_query_string_has_been_set_no_data_should_be_returned()
{
Livewire::withQueryParams(['post_id',rand()])
->test('posts')
->assertSee('title','')
->assertSee('text','')
->assertSee('save');
}
this test returns green! .. but in action this error comes up :
No query results for model [App\Models\Post] 444 (View: E:\---\livewire_CRUD\resources\views\welcome.blade.php)
I have implemented mount() in component like so :
public $posts, $post, $title, $text, $post_id;
protected $queryString = ['post_id'];
public function mount()
{
if ($this->post_id) {
$this->queryString['post_id'] = $this->post_id;
$this->edit($this->queryString['post_id']);
}
}
and edit method is :
public function edit($post_id)
{
$post = Post::findOrFail($post_id);
$this->editPost = true;
$this->title = $post->title;
$this->text = $post->text;
$this->post_id = $post->id;
$this->resetErrorBag();
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community