Vue-Test-Utils 的 "mount" 和 "shallowMount" 的区别?
The difference between Vue-Test-Utils' "mount" and "shallowMount"?
免责声明:我对 Vue、JavaScript 和一般的 Web 框架还很陌生。
我正在尝试使用 Jest 和 vue-test-utils 熟悉一些基本的单元和组件测试。
我已阅读 vue-test-utils
上的文档' mount() and shallowMount()
, 但我不确定什么时候使用一个而不是另一个(它们看起来非常相似)。
根据 shallowMount()
上的文档:
Like mount, it creates a Wrapper that contains the mounted and
rendered Vue component, but with stubbed child components.
"stubbed child components"到底是什么意思?
mount()
和 shallowMount()
可以互换使用吗?
文档中 "stubbed child components" 的意思是测试组件中的每个组件都不会被渲染。相反,您将拥有一个占位符组件。
这可以防止您的测试被其他组件的行为寄生。
在我看来,您应该在进行单元测试时始终浅安装组件,而在对整个应用程序进行测试时简单地安装它们。
免责声明:我对 Vue、JavaScript 和一般的 Web 框架还很陌生。
我正在尝试使用 Jest 和 vue-test-utils 熟悉一些基本的单元和组件测试。
我已阅读 vue-test-utils
上的文档' mount() and shallowMount()
, 但我不确定什么时候使用一个而不是另一个(它们看起来非常相似)。
根据 shallowMount()
上的文档:
Like mount, it creates a Wrapper that contains the mounted and rendered Vue component, but with stubbed child components.
"stubbed child components"到底是什么意思?
mount()
和 shallowMount()
可以互换使用吗?
文档中 "stubbed child components" 的意思是测试组件中的每个组件都不会被渲染。相反,您将拥有一个占位符组件。
这可以防止您的测试被其他组件的行为寄生。
在我看来,您应该在进行单元测试时始终浅安装组件,而在对整个应用程序进行测试时简单地安装它们。