Skip to content

Commit

Permalink
Merge pull request #1859 from GSA/hotfix-cypress-datalayer-action
Browse files Browse the repository at this point in the history
PXBF-hotfix-cypress-datalayer-action: add wait to avoid race condition
  • Loading branch information
XavierMetichecchia authored and scottqueen-bixal committed Oct 8, 2024
1 parent 4e40fcd commit 45ee688
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions benefit-finder/cypress/e2e/storybook/dataLayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,28 @@ describe('Calls to Google Analytics Object', function () {
.button()
.contains(EN_LOCALE_DATA.intro.button)
.then(() => {
// get the last pushed event
const ev = { ...window.dataLayer[window.dataLayer.length - 1] }
removeID(ev)
cy.wait(wait).then(() => {
assert.isDefined(
window.dataLayer.find(x => x.event === 'gtm.load'),
'GTM is done loading'
)
assert.isDefined(
window.dataLayer.find(x => x.event === 'bf_page_change'),
'bf_page_change is loaded'
)

expect(ev).to.deep.equal(dataLayerValueIntro)
cy.wait(500).then(() => {
console.log(window.dataLayer)
// get the last pushed event
const bfEventIndex = window.dataLayer.findIndex(
x => x.event === 'bf_page_change'
)
const ev = { ...window.dataLayer[bfEventIndex] }
removeID(ev)

expect(ev).to.deep.equal(dataLayerValueIntro)
})
})
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion usagov-2021
Submodule usagov-2021 updated 895 files

0 comments on commit 45ee688

Please sign in to comment.