Use toHaveText function when you want to check that an element's text is equal to the expected text
example
// could be used with Promise<ElementHandle>awaitexpect(page.$('.alert')).toHaveText('Success message');// or with ElementHandleconsttoastElement = awaitpage.$('.alert);awaitexpect(toastElement).toHaveText('Success message');// or using an array of page and selectorawaitexpect([page, '.alert']).toHaveText('Success message');// also you can check text ignoring case sensitiveawaitexpect(page.$('.alert')).toHaveText('success message', {ignoreCase:true})
Use
toHaveText
function when you want to check that an element's text is equal to the expected text