We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
在Vue Test Utils官网的shallowMount和常用技巧中分别都提到了下面的话
和 mount 一样,创建一个包含被挂载和渲染的 Vue 组件的 Wrapper,不同的是被存根的子组件。
Vue Test Utils 允许你通过 shallowMount 方法只挂载一个组件而不渲染其子组件 (即保留它们的存根)
这已经是两者区别的官网介绍的全部。我敢肯定只看这两句话肯定是一头雾水,任你vue技术再好水平再高,不通过实际单测实践,是完全不能理解其中的奥秘的。
此篇笔记将揭开mount和shallowMount之间不可告人的秘密 写这种零散笔记完全是因为没有时间更新仓库内容,对单测有兴趣的就将就着看吧。
<div><span><p>
<my-componet-stub></my-componet-stub>
渲染结果总结
mount刨根问底,祖宗十八代都不会放过,shallowMount仅限测试组件,不牵扯子组件内容
import myComponent from '~/myComponent' ... options:{ ... stubs:{ myComponent } }
//被测试组件内 ... <my-component> <template #body> <div> 自定义内容 </div> </template> </my-component> ...
使用场景总结
基本准则:所有使用shallowMount的地方都可以用mount替换,但是但凡能使用shallowMount的地方坚决不用mount;
无脑做法:snapshot测试中都使用mount,其他测试都使用shallowMount,测试不会太慢,但也不是最快 【追加】 基于编程的严谨性,非常不提倡这种无脑做法,建议全部使用shallowMount。且上面提到的必须使用mount的情况实际也是非必须的,对此也追加了说明
与stubs的总结
经常与shallowMount一起出现,只在不得不的场合才会跟mount一起出现。
stubs:['may-component']
shallowMount与stubs
stubs存在的话优先按照stubs内容渲染,不存在使用默认存根渲染。注意空存根与默认存根的区别
The text was updated successfully, but these errors were encountered:
博主总结的很好,感谢分享
Sorry, something went wrong.
nice
No branches or pull requests
结论写在最开始:尽一切努力使用shallowMount,远离mount
在Vue Test Utils官网的shallowMount和常用技巧中分别都提到了下面的话
这已经是两者区别的官网介绍的全部。我敢肯定只看这两句话肯定是一头雾水,任你vue技术再好水平再高,不通过实际单测实践,是完全不能理解其中的奥秘的。
此篇笔记将揭开mount和shallowMount之间不可告人的秘密
写这种零散笔记完全是因为没有时间更新仓库内容,对单测有兴趣的就将就着看吧。
<div><span><p>
之类<my-componet-stub></my-componet-stub>
渲染结果总结
mount刨根问底,祖宗十八代都不会放过,shallowMount仅限测试组件,不牵扯子组件内容
必须使用mount。下面将说明何种情况:当被测试组件内包含子组件,且子组件的dom结构通过slot在被测试组件内定义的时候,必须使用mount来测试snapshot。追加说明:此种情况也是可以使用shallowMount的,做法为:
----> 实际上所有测试都可以不使用mount,但是鉴于测试的复杂性,有可能会出现用shallowMount怎么也报错的情况,但是改成mount就能测试通过
使用场景总结
基本准则:所有使用shallowMount的地方都可以用mount替换,但是但凡能使用shallowMount的地方坚决不用mount;
无脑做法:snapshot测试中都使用mount,其他测试都使用shallowMount,测试不会太慢,但也不是最快【追加】 基于编程的严谨性,非常不提倡这种无脑做法,建议全部使用shallowMount。且上面提到的必须使用mount的情况实际也是非必须的,对此也追加了说明
与stubs的总结
经常与shallowMount一起出现,只在不得不的场合才会跟mount一起出现。
stubs:['may-component']
只声明了一个名字,则将may-component解析为一个空的存根,与默认存根不同哦shallowMount与stubs
stubs存在的话优先按照stubs内容渲染,不存在使用默认存根渲染。注意空存根与默认存根的区别
The text was updated successfully, but these errors were encountered: