diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index 3db714c91..44e9c2008 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -876,7 +876,10 @@ public function vueAttribute($componentSelector, $key) $fullSelector = $this->resolver->format($componentSelector); return $this->driver->executeScript( - "return document.querySelector('".$fullSelector."').__vue__.".$key + "var el = document.querySelector('".$fullSelector."');". + "return typeof el.__vue__ === 'undefined' ". + '? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).'.$key. + ': el.__vue__.'.$key ); } diff --git a/tests/MakesAssertionsTest.php b/tests/MakesAssertionsTest.php index 0e1a8db86..82cc47baf 100644 --- a/tests/MakesAssertionsTest.php +++ b/tests/MakesAssertionsTest.php @@ -346,6 +346,24 @@ public function test_assert_selected() } } + public function test_assert_vue_contains_formats_vue_prop_query() + { + $driver = m::mock(stdClass::class); + $driver->shouldReceive('executeScript') + ->with( + 'var el = document.querySelector(\'body [dusk="vue-component"]\');'. + "return typeof el.__vue__ === 'undefined' ". + '? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).name'. + ': el.__vue__.name' + ) + ->once() + ->andReturn(['john']); + + $browser = new Browser($driver); + + $browser->assertVueContains('name', 'john', '@vue-component'); + } + public function test_assert_vue_contains() { $driver = m::mock(stdClass::class);