I have created a feature test to test the admin registration. When i run the testcases it gives me this error
1) Tests\Feature\Admin\RegisterTest::testValidRegistration The expected [App\Events\UserRegistered] event was not dispatched. Failed asserting that false is true.
/var/www/html/gas-backend/tests/Feature/Admin/RegisterTest.php:85
Below i have stated the admin registration test file and user registered event file
Admin/RegisterTest.php
$response->assertStatus(201);
$response->assertJson($expectedResponse);
$this->assertDatabaseHas('users', $expectedDatabaseRecord);
Event::assertDispatched(UserRegistered::class);
Notification::assertNotSentTo($user, RegistrationComplete::class);
UserRegistered.php
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Models\User;
class UserRegistered
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
//return new PrivateChannel('channel-name');
}
}
How should i resolve this error ?
Aucun commentaire:
Enregistrer un commentaire