Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking request query parameters for Livewire #1618

Closed
faustbrian opened this issue Sep 16, 2020 · 6 comments
Closed

Mocking request query parameters for Livewire #1618

faustbrian opened this issue Sep 16, 2020 · 6 comments

Comments

@faustbrian
Copy link
Contributor

Description

Since Livewire 2.0 now has the ability to automatically fill properties from the query string, what would be the recommended way to test that Livewire picks up properties from the query string? Is there any easy way to set the query string before the Livewire component is mounted in a test so that it could pick up the query parameters?

Context

  • Livewire version: 2.2.3
  • Laravel version: 8.0
  • Browser: n/a
@faustbrian
Copy link
Contributor Author

@calebporzio any chance to get some help on this?

@austenc
Copy link
Collaborator

austenc commented Oct 16, 2020

@faustbrian If you want to test query string stuff, there are examples of how to do it in Livewire's tests.

See here:
https://github.com/austenc/livewire/blob/b92bef82525268ffbc6f761f4bab285fa3dd7105/tests/Browser/QueryString/Test.php#L11

Since that's tested by Livewire, testing it in your own code may be redundant, but that's your call. 👍

@faustbrian
Copy link
Contributor Author

Yeah I know how to do it with Dusk from the test suite but doing it in unit tests would be my use-case.

@nuernbergerA
Copy link
Contributor

Could you provide some sudo code?

So we know how you would imagine an API for this should look like.

I don't think that's possible without dusk but you never know 🙂

@calebporzio
Copy link
Collaborator

Good call @faustbrian, I think it would be handy to have a way to do this in Livewire's testing utilities.

In the past, I've used more outside-in approaches to assert that Livewire handled a query string setter.

Here's some not-tested-off-the-top-of-my-head code:

$this->get('/the-url/with/the/livewire/component?foo=bar')
    ->assertSee('bar'); // Assuming that `$foo` is echoed out on the page

Other than this I'm not sure what the API would be for the testing utilities.

Maybe something like this?

Livewire::withQueryParams(['foo' => 'bar'])->test('livewire-component');

Because this isn't a bug necessarily, I'm going to close this issue. Open to a PR thought.

@faustbrian
Copy link
Contributor Author

Bit busy at the moment but I'll try to take a stab at a PR when I find time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants