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

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Mar 24, 2022

Sample app with Breeze components to test these changes: derekmd/vue3-dusk-test@b111b48

Methods assertVue(), assertVueIsNot, assertVueContains, and assertVueDoesNotContain can fail in apps using Vue 3's newer composition API.

When fetching a component prop, attempt these paths:

  1. el.__vue__.key
    • Vue 2
  2. el.__vueParentComponent.ctx.key
    • Vue 3 options API
    • Vue 3 composition API for definedProps()
  3. el.__vueParentComponent.setupState.key [added in this PR]
    • Vue 3 composition API reactive(), computed(), or any other <script setup> variables.

If the ctx key is undefined, the setupState fallback is attempted. Wrap in a try/catch for attempts to access undefined nested props like el.__vueParentComponent.ctx.form.email with no defined el.__vueParentComponent.ctx.form.


This also fixes #968 by removing JSON serialization of el.__vueParentComponent.ctx. When I submitted PR #834, the JSON.parse(JSON.stringify(...)) snippet was taken from a forum post I read about the Vue 3 equivalent of Vue 2's el.__vue__. The JSON transformation evaluates Vue prop getters and strips functions for a simple cloned payload. e..g,

console-log-ctx

This wouldn't be needed when fetching one component prop at runtime. It maybe cleaned up the output of console.log(JSON.parse(JSON.stringify(el.__vueParentComponent.ctx))) if any developer edits vendor/laravel/dusk/src/Concerns/MakeAssertions.php method vueAttribute() in debug dump desperation. Otherwise I don't see a reason to keep this in place. Removing this now won't affect passing test suite assertions of existing Laravel apps.

If Vue's composition API used, reactive data and computed props cannot
be inspected through these methods.

When fetching a component prop, attempt these paths:

1. el.__vue__.key
   * Vue 2
2. el.__vueParentComponent.ctx.key
   * Vue 3 options API
   * Vue 3 composition API for definedProps()
3. el.__vueParentComponent.setupState.key
   * Vue 3 composition API reactive(), computed(), or any other
     <script setup> variables.

If the ctx key is undefined, the setupState fallback is attempted.
Wrap in a try/catch for attempts to access undefined nested props which
could throw an error.
@taylorotwell
Copy link
Member

Thanks!

@taylorotwell taylorotwell merged commit f62afe1 into laravel:6.x Mar 24, 2022
@derekmd derekmd deleted the vue-3-composition-api branch March 24, 2022 15:03
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.

[6.22] [vueAttribute/assertVue] javascript error: Converting circular structure to JSON
2 participants