DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

Why I cannot assert that the job has been dispatched?

In my tests I need to assert that a specific job has been dispatched but without actually dispatching the job.

I used Bus::fake but as I ask bellow I have some troubles to assert that the job has been dispatched.

I have the following Laravel Controller:

namespace App\Controller
use App\Jobs\MyJob;

class JobDispatchControler
{
   public function callJob(Request $request)
   {
     MyJob::dispatch();
   }
}

The controller above has the following route:

Route::get('/job',"\App\Controller\JobDispatchControler@callJob");

And I want to test whether I a call to the /job will dispatch the MyJob job:

namespace Test\App\MyJob;

use Illuminate\Foundation\Testing\TestCase;

A silorar problem of mine is the following as well:

https://laracasts.com/discuss/channels/testing/why-i-am-unable-to-assert-that-a-job-has-not-been-dispatched

Top comments (0)