During testing a vue component in jest document.querySelector always returns null
You have to attach it to the DOM explicitly:
const wrapper = shallow(Component, {
// ...
attachToDocument: true
})
As of June 2020, vue-test-utils 1.3 has deprecated the use of attachToDocument. The solution that now works for me (as I had the same issue) is to replace it with:
const wrapper = shallow(Component, {
// ...
attachTo: document.body
});
You also need to call wrapper.destroy()
at the end of your test so it doesn't affect the others.