测试套件无法运行 TypeError:无法设置 null Running in Jest 的属性“content" [英] Test suite failed to run TypeError: Cannot set property 'content' of null Running in Jest

查看:20
本文介绍了测试套件无法运行 TypeError:无法设置 null Running in Jest 的属性“content"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基于 Vue 的项目的测试,我是框架 Jest 和 Vue 测试实用程序的新手,我还没有找到类似问题的解决方案,我尝试了几个组件,但错误总是相似

>

example.test.js

从'@vue/test-utils'导入{shallowMount}从 './Foo.vue' 导入 Foo描述('Foo',()=> {it('渲染一个 div', () => {const 包装器 = 浅安装(Foo)期望(wrapper.contains('div')).toBe(true)})})

<代码>● 测试套件运行失败类型错误:无法设置 null 的属性内容"6 |让 apiBaseUrl = document.head.querySelector('meta[name="apiBaseUrl"]');7 |如果(!apiBaseUrl){>8 |apiBaseUrl.content = '/api/';|^9 |}10 |11 |让 newAxios = axios.create({

api.js

let apiBaseUrl = document.querySelector('meta[name=apiBaseUrl"]');如果(!apiBaseUrl){apiBaseUrl.content = '/api/';}让 newAxios = axios.create({标题:{//IE11 的修复 - 我们需要定义 Pragma 标头Pragma: '无缓存',//'X-Requested-With': 'XMLHttpRequest'},withCredentials: 真,baseURL: apiBaseUrl.content,paramsSerializer:函数(参数){返回 qs.stringify(params)}});

index.html

<元字符集=utf-8"><meta http-equiv="X-UA-Compatible";内容=IE=边缘"><元名称=视口"内容=宽度=设备宽度,初始比例=1.0"><meta name="apiBaseUrl";内容=<%= VUE_APP_BASE_API_URL %>"><link rel="icon";href=<%= BASE_URL %>favicon.ico"><title>test</title>

这是我的组件的真实代码,允许用户识别