我该如何使用Jest测试HTML字符串?
目前,我是通过像下面这样的普通字符串比较来进行测试的。当我运行这个测试用例时,它能正常工作。
it('should compile partial as per the context', () => {
const receivedOutput = someFunctionReturningHTMLString();
//*PS: someFunctionReturningHTMLString() is function which returns a html string;*
//In above call, lets assume it returns `<a href="/" class="some_class1 some_class2" >`
const expectedResult = `<a href="/" class="some_class1 some_class2" >`;
expect(receivedOutput .trim()).toEqual(expectedResult.trim())
});
然而,我并不认为仅测试纯字符串值是一种好的方法。
有没有人能帮我找到更好的方式,可以实际测试HTML字符串中的内容?例如测试字符串中的特定类是否具有``标签?就像我们可以使用Enzyme测试React组件一样。