Javascript $root被shallowMount包装器$root覆盖
我在对Vue组件进行单元测试时遇到问题 我需要覆盖由Javascript $root被shallowMount包装器$root覆盖,javascript,unit-testing,vue.js,Javascript,Unit Testing,Vue.js,我在对Vue组件进行单元测试时遇到问题 我需要覆盖由shallowMount函数创建的$root 我有一个插件组件,它将其$roots数据分配给其本地数据: data() { return { noStoreNotifications: [], isHistoryOpen: false, pluginSettingWithoutStore: this.$root._pluginSetting.withoutStore, pluginSettingShowNot
shallowMount
函数创建的$root
我有一个插件组件,它将其$root
s数据分配给其本地数据:
data() {
return {
noStoreNotifications: [],
isHistoryOpen: false,
pluginSettingWithoutStore: this.$root._pluginSetting.withoutStore,
pluginSettingShowNotification: this.$root._pluginSetting.showHistory,
pluginSettingMaxHistoryLength: this.$root._pluginSetting.maxHistoryLength,
pluginSettingReverseHistory: this.$root._pluginSetting.reverseHistory,
};
},
由于这个插件在多个存储库中使用,具有不同的组件和用例,因此我需要能够访问它的包装器以从中获取一些数据
这个插件工作得很好,但是它的单元测试并不像我期望的那样工作,但是它为什么不工作是有道理的
正如我所写的,我需要通过$root
访问组件包装器对象。
通常我会使用:
cosnt data = {
mocks: {
$root: {
_eventHub: new Vue(),
_notificationContainer: null,
_pluginSetting: {},
},
},
}
在组件的初始安装范围内
const wrapper = shallowMount(Notifications, data);
但是这不起作用,因为shallowMount
方法创建了一个具有自己唯一的$root
的包装器,它覆盖了我的
在创建组件之前,是否有方法将其$root
覆盖到我的规范中