From 6a6c64fd6544f8c27ad2b7533a27d34ede3b8436 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 2 Apr 2019 18:47:15 +0200 Subject: [PATCH] Fix assertVueContains This fixes the assertVueContains and assertVueDoesNotContain methods to properly check for an array and what it contains instead of checking for a string. This got broken in https://github.com/laravel/dusk/commit/1985616f82b702f29f9a302657e6bf3f65c5e8de Fixes https://github.com/laravel/dusk/issues/637 --- src/Concerns/MakesAssertions.php | 14 +++++----- tests/MakesAssertionsTest.php | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index 031a68ee8..6ff3b227c 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -737,9 +737,10 @@ public function assertVueIsNot($key, $value, $componentSelector = null) */ public function assertVueContains($key, $value, $componentSelector = null) { - PHPUnit::assertTrue( - Str::contains($this->vueAttribute($componentSelector, $key), $value) - ); + $attribute = $this->vueAttribute($componentSelector, $key); + + PHPUnit::assertIsArray($attribute, "The attribute for key [$key] is not an array."); + PHPUnit::assertContains($value, $attribute); return $this; } @@ -755,9 +756,10 @@ public function assertVueContains($key, $value, $componentSelector = null) */ public function assertVueDoesNotContain($key, $value, $componentSelector = null) { - PHPUnit::assertFalse( - Str::contains($this->vueAttribute($componentSelector, $key), $value) - ); + $attribute = $this->vueAttribute($componentSelector, $key); + + PHPUnit::assertIsArray($attribute, "The attribute for key [$key] is not an array."); + PHPUnit::assertNotContains($value, $attribute); return $this; } diff --git a/tests/MakesAssertionsTest.php b/tests/MakesAssertionsTest.php index 5bac2a05f..2653d4526 100644 --- a/tests/MakesAssertionsTest.php +++ b/tests/MakesAssertionsTest.php @@ -198,4 +198,48 @@ public function test_assert_selected() ); } } + + public function test_assert_vue_contains() + { + $driver = m::mock(stdClass::class); + $driver->shouldReceive('executeScript')->andReturn(['john']); + + $resolver = m::mock(stdClass::class); + $resolver->shouldReceive('format')->with('@vue-component')->andReturn('body foo'); + + $browser = new Browser($driver, $resolver); + + $browser->assertVueContains('users', 'john', '@vue-component'); + + try { + $browser->assertVueDoesNotContain('users', 'john', '@vue-component'); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertStringContainsString( + "Failed asserting that an array does not contain 'john'.", + $e->getMessage() + ); + } + } + + public function test_assert_vue_contains_with_no_result() + { + $driver = m::mock(stdClass::class); + $driver->shouldReceive('executeScript')->andReturn(null); + + $resolver = m::mock(stdClass::class); + $resolver->shouldReceive('format')->with('@vue-component')->andReturn('body foo'); + + $browser = new Browser($driver, $resolver); + + try { + $browser->assertVueContains('users', 'john', '@vue-component'); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertStringContainsString( + 'The attribute for key [users] is not an array.', + $e->getMessage() + ); + } + } }