如果运行我的笑话测试套件,我会遇到问题。 网站说明,我正在使用vue-test-utils。 我的Vue数据如下所示:
data() {
return {
token: document.head.querySelector('meta[name="csrf-token"]'),
};
},
我的要素是这样:
<input
type="hidden"
name="_token"
:value="token.content"
>
如果我运行此测试套件:
beforeEach(() => {
const csrfToken = 'mocked-csrf-token';
document.head.innerHTML = `<meta name="csrf-token" content="${csrfToken}">`;
wrapper = shallowMount(NavbarDropdownProfileFooter, { attachToDocument: true });
});
我收到此错误:
TypeError: Cannot read property 'content' of null
答案 0 :(得分:0)
您的问题在于选择main.rs
元素。您的选择结果为return http.get(Uri.encodeFull(baseUrl), headers: {
"Content-Type": "application/json",
}).then((response) {
return json.decode(utf8.decode(response.bodyBytes));
});
,因此得到了描述的meta
。 null
元素并不特殊。删除对TypeError
道具的访问。
meta