laravel / browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.
MIT License
508 stars 75 forks source link

Assert response is json broken in v6 #159

Closed bytestream closed 2 years ago

bytestream commented 2 years ago

Description:

In v6 seeJson() is no longer possible and produces:

TypeError : Argument 1 passed to Laravel\BrowserKitTesting\TestCase::seeJsonEquals() must be of the type array, null given

Broken by https://github.com/laravel/browser-kit-testing/commit/d472e1c8f0d11614106db9c75435bdaf723e3290 which proclaimed:

This mainly aim to check if response is actually JSON.

This is what the reproducer below also intends to do.

Steps To Reproduce:

$this->json('GET', route('???'))
            ->seeJson()
            ->assertResponseOk();
driesvints commented 2 years ago

I'm not sure I understand? Your issue is with seeJsonEquals which only accepts an array. How does this affect seeJson?

bytestream commented 2 years ago

https://github.com/laravel/browser-kit-testing/blob/2dfb9c0fc65ad224d689899506155274fd640cb5/src/Concerns/MakesHttpRequests.php#L418

@driesvints seeJson() defaults $data to null which is passed to seeJsonEquals.

https://github.com/laravel/browser-kit-testing/blob/2dfb9c0fc65ad224d689899506155274fd640cb5/src/Concerns/MakesHttpRequests.php#L421

The response returns valid JSON, which is how it falls through to seeJsonEquals(null)

driesvints commented 2 years ago

Okay I see what you mean. Thanks, we'll check in on that.

driesvints commented 2 years ago

Fixed. Will be in tomorrow's release: https://github.com/laravel/browser-kit-testing/pull/160

bytestream commented 2 years ago

Great thanks :+1: