beyondcode / dusk-dashboard

A beautiful dashboard for your Laravel Dusk tests
https://pociot.dev/8-introducing-laravel-dusk-dashboard
MIT License
559 stars 63 forks source link

When using Components, always getting a "call to a member function collect() on null" error #50

Closed nie7321 closed 10 months ago

nie7321 commented 5 years ago

When I use a component and a $browser->within(new MyComponent, . . .), I'm always getting an error:

    public function test_dashboard_available()
    {
        $this->browse(function (Browser $browser) {
            $browser->within((new Multiselect('#search-status-selector')), function ($browser) {
                $browser->clickOption(3);
            });
        });
    }

Resulting in:

Error: Call to a member function collect() on null

/home/vagrant/code/dusk-dashboard/src/Dusk/Concerns/MakesAssertions.php:262
/home/vagrant/code/a-nice-project/tests/Browser/Components/Bootstrap/Multiselect.php:39

I think the problem is that the Laravel\Dusk\Browser is just doing a new static() to make a Browser for the component -- it doesn't know that it needs to call setActionCollector().

I can work around the bug by passing the BrowserActionCollector through from the test case, and then calling setActionCollector myself before the component uses the browser instance, but this is kinda gross.

I'm not sure what the right way to solve this is!