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

[6.x] assertVue*() methods support Vue 3 composition API #969

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,14 @@ public function vueAttribute($componentSelector, $key)

return $this->driver->executeScript(
"var el = document.querySelector('".$fullSelector."');".
"return typeof el.__vue__ === 'undefined' ".
'? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).'.$key.
': el.__vue__.'.$key
"if (typeof el.__vue__ !== 'undefined')".
' return el.__vue.'.$key.';'.
'try {'.
' var attr = el.__vueParentComponent.ctx.'.$key.';'.
" if (typeof attr !== 'undefined')".
' return attr;'.
'} catch (e) {}'.
'return el.__vueParentComponent.setupState.'.$key.';'
);
}
}
37 changes: 26 additions & 11 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,15 @@ public function test_assert_vue()
$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')
->with(
'var el = document.querySelector(\'body foo\');'.
"return typeof el.__vue__ === 'undefined' ".
'? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).foo'.
': el.__vue__.foo'
"var el = document.querySelector('body foo');".
"if (typeof el.__vue__ !== 'undefined')".
' return el.__vue.foo;'.
'try {'.
' var attr = el.__vueParentComponent.ctx.foo;'.
" if (typeof attr !== 'undefined')".
' return attr;'.
'} catch (e) {}'.
'return el.__vueParentComponent.setupState.foo;'
)
->twice()
->andReturn('foo');
Expand Down Expand Up @@ -1071,10 +1076,15 @@ public function test_assert_vue_is_not()
$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')
->with(
'var el = document.querySelector(\'body foo\');'.
"return typeof el.__vue__ === 'undefined' ".
'? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).foo'.
': el.__vue__.foo'
"var el = document.querySelector('body foo');".
"if (typeof el.__vue__ !== 'undefined')".
' return el.__vue.foo;'.
'try {'.
' var attr = el.__vueParentComponent.ctx.foo;'.
" if (typeof attr !== 'undefined')".
' return attr;'.
'} catch (e) {}'.
'return el.__vueParentComponent.setupState.foo;'
)
->twice()
->andReturn('foo');
Expand Down Expand Up @@ -1125,9 +1135,14 @@ public function test_assert_vue_contains_formats_vue_prop_query()
$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'
"if (typeof el.__vue__ !== 'undefined')".
' return el.__vue.name;'.
'try {'.
' var attr = el.__vueParentComponent.ctx.name;'.
" if (typeof attr !== 'undefined')".
' return attr;'.
'} catch (e) {}'.
'return el.__vueParentComponent.setupState.name;'
)
->once()
->andReturn(['john']);
Expand Down