I am trying to write an end-to-end test which checks if a p tag exists containing some specific text:
it('should display search result snippet for a result item', function() {
input('query').enter('One');
element('#submitSearchButton').click();
expect(element('.emails li p').text()).toEqual('This is a search result snippet for email one')
})
However I get:
expected "This is a search result snippet for email one" but was "\n\t\t\t\t\t\tThis is a search result snippet for email one\n\t\t\t\t\t"
How can I check that the page contains the text required?
Edit:
Ok, I see this is because I am testing something that is in an HTML template. This template has formatting to make it easier to read but I got confused because I was looking at the rendered web page in a browser:
<p>
{{email.snippet}}
</p>
My question now is how should I go about testing in an angular e2e test that my email snippet is rendered as expected? Should I re-format the template or should I be going about this in a different way?
I'm not sure why your code look like that. In jQuery to check if p contain some text you just need to do:
if ($('p:contains("someText")').length > 0) {
// Your code here
}