Jestjs Vue3/Jest-测试过程中的换行问题

Jestjs Vue3/Jest-测试过程中的换行问题,jestjs,vuejs3,Jestjs,Vuejs3,我试图在测试中模拟鼠标悬停,但在expect中使用.contain时出现问题。由于页面呈现,测试未通过 以下是测试结果: Expected substring: "<div id=\"title\"><!--v-if--></div>" Received string: "<div id=\"title\"> <!--v-if--> </div>

我试图在测试中模拟鼠标悬停,但在expect中使用.contain时出现问题。由于页面呈现,测试未通过

以下是测试结果:

Expected substring: "<div id=\"title\"><!--v-if--></div>"
Received string:    "<div id=\"title\">
  <!--v-if-->
</div>"
所需的子字符串:“
收到的字符串:“
"
这是我的代码:

describe('mouse event', function() {


test('over change', async (done) => {
    const Component = defineComponent({
      template: '<div id="title" @mouseover="hoveredIcon"><span v-if="hovered">Hello World</span></div>',
      data() {
        return {
          hovered: false,
        }
      },
      methods: {
        hoveredIcon() {
          this.hovered = true
        },
      }
    })
    const wrapper = mount(Component)
    expect(wrapper.html()).toContain('"<div id=\"title\"><!--v-if--></div>"')
    wrapper.find("#title").trigger("mouseover");
    wrapper.vm.$nextTick( () => {
      expect(wrapper.html()).toContain('<div id=\"title\"><span>Hello World!</span></div>')
      done();
    });
  })
})
description('mouse event',function()){
测试('over change',异步(完成)=>{
常量组件=定义组件({
模板:“你好,世界”,
数据(){
返回{
悬停:错,
}
},
方法:{
霍维迪肯{
this.hovered=true
},
}
})
常量包装=装载(组件)
expect(wrapper.html()).toContain(“”)
wrapper.find(“#title”).trigger(“mouseover”);
wrapper.vm.$nextTick(()=>{
expect(wrapper.html()).toContain('Hello World!')
完成();
});
})
})
如何在一行中获取收到的字符串?或者如何使期望的部分在几行中完美匹配

expect(wrapper.html()).toContain('<div id="title"><!--v-if--></div>')
expect(wrapper.html()).toContain(“”)

expect(wrapper.html()).toContain('
')
有更好的解决办法吗


感谢您的帮助

找到的一个解决方案是直接使用\n预期值。 expect(wrapper.html()).toContain('\n\n')

expect(wrapper.html()).toContain('<div id="title">
      <!--v-if-->
      </div>')