Before you begin
The examples shown below are based on two key assumptions:
- That you have already create a basic automated test using our getting started guides.
- You have a chosen assertion library that you will use to test the values shown below.
Links within email HTML content
When an email is sent with an HTML body, Mailosaur automatically extracts any hyperlinks found within anchor (<a>
) and area (<area>
) elements and makes these available via the html.links
array.
Each link has a text
property, representing the display text of the hyperlink within the body, and an href
property containing the target URL.
Note that only links that have been correctly marked up in HTML will be detected.
// How many links?
console.log(message.html.links.length) // 2
const firstLink = message.html.links[0]
console.log(firstLink.text) // "Google Search"
console.log(firstLink.href) // "https://www.google.com/"
Links within email and SMS text content
As with links found within the HTML content of an email, Mailosaur also detects and extracts links found within the plain text of a message (both email and SMS).
These are made available viable via the text.links
array.
Each link has an href
property containing the target URL. Whilst each link also has a text
property, this will always have the same value as href
.
// How many links?
console.log(message.text.links.length) // 2
const firstLink = message.text.links[0]
console.log(firstLink.href) // "https://www.google.com/"