Skip to content

Conversation

@claudiodekker
Copy link
Contributor

@claudiodekker claudiodekker commented Dec 26, 2021

This PR deprecates the assertion library introduced in #220.

Because we added Inertia's assertions to Laravel's core in laravel/framework#36454, it no longer makes sense to maintain two separate versions of this. While it is true that Inertia pioneerd this assertion library, it has since matured as part of the Laravel framework.

In addition to reducing the maintenance effort for the Inertia team, the Laravel variant (by now) also has more features that users might want, it's properly documented, and has the benefit of automatically inheriting assertion macros that are registered by installed third-party packages.

Differences

Do not worry, the Laravel variant is nearly identical. Here's all the differences:

  • The parameter type is different
  • The misses / missesAll methods are named missing and missingAll instead
  • Inertia-specific methods (component, url, version) are only available on the top-level when using the new AssertableInertia class, or when using $response->assertInertia(function ($inertia) {
  • The Laravel / new variant has additional methods: whereType, whereContains, each and the ability to do shorthand-scoping without counting

Deprecating Assert

Right now (Dec 26th, 2021) the Assert version is still available, and the AssertableInertia is only automatically used on Laravel 8.32 or newer, but a deprecation notice/error will be shown during tests.

In addition, strict parameter type hints will crash in existing tests. To solve this quickly, you can alias your import:

// Before
use Inertia\Testing\Assert;

// After
use Inertia\Testing\AssertableInertia as Assert; 

@claudiodekker claudiodekker merged commit f697368 into master Dec 26, 2021
@claudiodekker claudiodekker deleted the use-assertablejson branch December 26, 2021 19:03
@claudiodekker claudiodekker changed the title Migrate to AssertableJson (Laravel-core) DeprecateAssert in favor of Laravel's AssertableJson Dec 26, 2021
@claudiodekker claudiodekker changed the title DeprecateAssert in favor of Laravel's AssertableJson Deprecate Assert in favor of Laravel's AssertableJson Dec 26, 2021
@RobertBoes
Copy link
Contributor

Does this mean AssertableInertia and $this->assertInertia() will also be depricated somewhere in the future? Because this also changes how we're supposed to write tests, previously we could use this:

$this->get('/home')
  ->assertOk()
  ->assertInertia(
    fn (Assert $page) => $page
      ->component('Home')
  );

Note the "normal" request, not explicitly requesting JSON.

With this change we now have to instruct to use JSON and pass the X-Inertia header, because otherwise no JSON would be returned and these assertions won't work. Previously Inertia took this into account, because all props are available in the Inertia response as "sort of JSON", without Inertia assertions it would look like this:

$this->getJson('/home', ['X-Inertia' => true])
  ->assertOk()
  ->assertJson(
    fn (AssertableJson $page) => $page
      ->component('Home')
  );

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

Successfully merging this pull request may close these issues.

3 participants