From 51484467451183dce2e2120ba54d651a9fd1b38e Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Thu, 28 Nov 2019 17:50:58 +1100 Subject: [PATCH] fix(iframe-fixes): add test (#21) Fixes #18 --- cypress/integration/unit/iframe-fixes.ts | 5 +++++ lib/iframe-fixes.ts | 2 +- src/document-manipulator/document-manipulator.ts | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cypress/integration/unit/iframe-fixes.ts b/cypress/integration/unit/iframe-fixes.ts index 7d10868..53d0b2a 100644 --- a/cypress/integration/unit/iframe-fixes.ts +++ b/cypress/integration/unit/iframe-fixes.ts @@ -21,6 +21,11 @@ describe('IframeFixes', () => { cy.get('.bodyAppendChild').should('exist'); }); + it('Check document.body.removeChild override is active', () => { + component.create(bootstrap); + cy.get('.bodyAppendAndRemoveChild').should('not.exist'); + }); + it('Check document.querySelector override is active', () => { component.create(bootstrap); cy.get('.documentQuerySelectorSuccess').should('exist'); diff --git a/lib/iframe-fixes.ts b/lib/iframe-fixes.ts index 3d064d0..c4121da 100644 --- a/lib/iframe-fixes.ts +++ b/lib/iframe-fixes.ts @@ -69,7 +69,7 @@ function overrideSpecIFrameToApplyToAppIFrame(): void { // end up causing "The node to be removed is not a child of this node." errors. { const bodyRemoveChild = function (this: T): T { - return appDocument.body.removeChild.apply(appDocument, arguments as any) as T; + return appDocument.body.removeChild.apply(appDocument.body, arguments as any) as T; }; if (specDocument.body.removeChild !== bodyRemoveChild) { specDocument.body.removeChild = bodyRemoveChild; diff --git a/src/document-manipulator/document-manipulator.ts b/src/document-manipulator/document-manipulator.ts index 16dbc62..20c5bba 100644 --- a/src/document-manipulator/document-manipulator.ts +++ b/src/document-manipulator/document-manipulator.ts @@ -22,6 +22,13 @@ export class DocumentManipulator { document.body.appendChild(el); } + { + const el = document.createElement('div'); + el.classList.add('bodyAppendAndRemoveChild'); + el.textContent = '- bodyAppendAndRemoveChild'; + document.body.appendChild(el); + } + { const el = document.querySelector('document-manipulator'); if (el) {