Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Handle cases where the headings do not appear on the page
Browse files Browse the repository at this point in the history
The body of a guide is rendered using a shared ‘GovSpeak’ component.

In test mode shared components are not fetched from Static. Instead they are rendered as a dummy tag which contains a JSON dump of the locals - the arguments passed to the component.

This means that the headings we expect to be present on the page (within the body of the guide) are not present. This which was causing JavaScript errors on the page, which were appearing in unrelated tests that used the Javascript driver to execute.

By returning early if we cannot get the offset of a heading we guard against this.
  • Loading branch information
36degrees authored and gemmaleigh committed Oct 25, 2016
1 parent 95c390d commit 53bdd74
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@
var $theID = $(theID)
var $theNextID = $(theNextID)

var headingPosition = self.getHeadingPosition($theID).top
var headingPosition = self.getHeadingPosition($theID)

if (!headingPosition) {
return
}

headingPosition = headingPosition.top
headingPosition = headingPosition - 53 // fix the offset from top of page

if (theNextID) {
Expand Down

0 comments on commit 53bdd74

Please sign in to comment.