Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Assert that a component has rendered on a page #2650

Open
ahinkle opened this issue Jun 25, 2021 · 0 comments
Open

Assert that a component has rendered on a page #2650

ahinkle opened this issue Jun 25, 2021 · 0 comments

Comments

@ahinkle
Copy link

ahinkle commented Jun 25, 2021

I'm finding a need to check if a component has processed on the page.

I can always test if the HTML/text shows within the page but sometimes I want to test if a component was rendered within the page and assert that the variables are defined correctly from the passed variables.

If anyone would find this useful I would be happy to work on it and open a pull request.

Important to note: We already have testing to evaluate and render a single Blade component via $this->component(). This is outside the scope of the single component render and coming from the application get() request.

    // use App\View\Components\SomeComponent;

    public function it_does_something_really_cool_and_shows_the_component()
    {
        $this->get('/my-page')
            ->assertOk()
            ->assertSeeComponent(SomeComponent::class);

            // Assert that a component was not rendered on the page:
            ->assertMissingComponent(SomeComponent::class);

            // Access the component properties which must evaluate to true.
            ->assertSeeComponent(SomeComponent::class, function ($component) {
                return $component->title === 'My Page Title';
            });
    }
@ahinkle ahinkle changed the title Assert that a component has loaded on a page Assert that a component has rendered on a page Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant