php – How to resolve 'The expected [App\Events\UserRegistered] event was not dispatched.' error?-ThrowExceptions

Exception or error:

I have created a feature called 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.


Below i have stated the admin registration test file and user registered event file


        $this->assertDatabaseHas('users', $expectedDatabaseRecord);
        Notification::assertNotSentTo($user, RegistrationComplete::class);



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 ?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *