sazvader's avatar

How to test that a job was dispatched from running a command?

I am trying to test that a job was dispatched from running a command. But, the test is failing with The excepted job was not dispatched exception. Below is what my test looks like.

 	public function it_dispatches_a_job()
    {
        Bus::fake();

        $records = $this->user->records;

        $this->artisan('run-job');

        Bus::assertDispatched(function (ExampleJob $job) use ($records) {
            return $job->total === $records->sum('total');
        });
    }
0 likes
2 replies
kevinbui's avatar
kevinbui
Best Answer
Level 41

Maybe the condition within the closure is not met. Does the test case pass if it is simply like this:

Bus::assertDispatched(ExampleJob::class);
1 like

Please or to participate in this conversation.