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

feat(stubs): Allow to stub directives (fixes #1800) #1804

Merged
merged 3 commits into from Oct 17, 2022
Merged

Conversation

xanf
Copy link
Collaborator

@xanf xanf commented Oct 9, 2022

We're adding new vnode transformer (related to directives) and re-use our architecture for searching stubs to make sure that we still could find elements even after stubbing directives on them

@netlify
Copy link

netlify bot commented Oct 9, 2022

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 696a1a1
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/634afbf7e666d90008c3eaad
😎 Deploy Preview https://deploy-preview-1804--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

* this adds stubbing directives functionality to @vue/test-utils
docs/guide/advanced/stubs-shallow-mount.md Outdated Show resolved Hide resolved
docs/guide/advanced/stubs-shallow-mount.md Outdated Show resolved Hide resolved
docs/guide/advanced/stubs-shallow-mount.md Show resolved Hide resolved
src/mount.ts Outdated Show resolved Hide resolved
src/stubs.ts Show resolved Hide resolved
src/utils/find.ts Outdated Show resolved Hide resolved
tests/mountingOptions/global.stubs.spec.ts Show resolved Hide resolved
},
template: '<div v-my-directive>text</div>',
directives: { MyDirective }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naive question: shouldn't that use a "real" script setup SFC like other tests do? That would seem more bulletproof and close to reality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Why not, I have no strong opinion on this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💣 Actually this one demonstrated that directives stubbing won't work with <script setup>. I will probably go ahead and create an issue for <script setup> compiler (I believe we could easily do that there), but for now I just capture current state of the things

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test should be updated to reflect that it does not currently work right?
And ideally, reference the issue you'll create for the compiler, so we can fix it when possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cexbrayat nope. { setup() ... { ... }} will still work, <script setup> will not. I've added link to vuejs/core#6887 with my proposal to docs to reflect that

* fix wording
* fix tests
* improve types
docs/guide/advanced/stubs-shallow-mount.md Outdated Show resolved Hide resolved
src/vnodeTransformers/stubDirectivesTransformer.ts Outdated Show resolved Hide resolved
},
template: '<div v-my-directive>text</div>',
directives: { MyDirective }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test should be updated to reflect that it does not currently work right?
And ideally, reference the issue you'll create for the compiler, so we can fix it when possible.

Copy link
Member

@cexbrayat cexbrayat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Ideally I'd like another pair of eyes on this before merging it

@freakzlike @lmiller1990 would you mind taking a look when you have some time?

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me!

@cexbrayat cexbrayat merged commit 99209d0 into main Oct 17, 2022
@cexbrayat cexbrayat deleted the xanf-feat-stub branch October 17, 2022 05:29
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.

None yet

3 participants