How do I test a HTML string using Jest?
Right now, I am doing it using regular string comparison like below. When I run this test case, it works fine.
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())
});
However, I don't find this approach of testing pure string values as a good approach.
Can somebody help me with a better way where I can actually test the content of the HTML string? Like testing whether the tag in the string has a particular class? Something like what we can achieve with Enzyme for React components.