diff --git a/cypress/fixtures/elements.html b/cypress/fixtures/elements.html
new file mode 100644
index 00000000..5d00fa84
--- /dev/null
+++ b/cypress/fixtures/elements.html
@@ -0,0 +1,21 @@
+
+
+
+ Elements example
+
+
+
+
+
+
+
diff --git a/cypress/fixtures/event-informer.js b/cypress/fixtures/event-informer.js
new file mode 100644
index 00000000..f125f61a
--- /dev/null
+++ b/cypress/fixtures/event-informer.js
@@ -0,0 +1,13 @@
+window.informEventCypress = (event, type = event.type) => {
+ if (window.Cypress) {
+ return fetch(`http://cypress.test/events/${type}`, {
+ body: JSON.stringify(event),
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
+ }
+
+ return Promise.resolve();
+};
diff --git a/cypress/integration/elements.spec.ts b/cypress/integration/elements.spec.ts
index 4353d898..1362ceb0 100644
--- a/cypress/integration/elements.spec.ts
+++ b/cypress/integration/elements.spec.ts
@@ -11,11 +11,26 @@ context('Elements example', () => {
window.BasisTheory.elements = window.BasisTheoryElements;
}`,
});
- cy.visit('examples/elements.html');
+ cy.visit('cypress/fixtures/elements.html');
cy.on('window:alert', (val) => {
expect(val).to.equal(
`BasisTheoryElements 04ab9d12-4959-4c48-ba03-9ef722efcc5a https://elements.basistheory.com`
);
});
});
+ it('should handle blocked BasisTheoryElements script request', () => {
+ cy.intercept(`http://cypress.test/events/initError`, (req) => {
+ req.reply({});
+ }).as(`initErrorEvent`);
+ cy.intercept(/https:\/\/.+?\/elements/u, {
+ statusCode: 400,
+ });
+ cy.visit('cypress/fixtures/elements.html');
+ cy.wait('@initErrorEvent')
+ .its('request.body')
+ .should(
+ 'equal',
+ 'There was an unknown error when loading Basis Theory Elements. Check the console for details.'
+ );
+ });
});
diff --git a/examples/elements.html b/examples/elements.html
deleted file mode 100644
index 0dc57d8b..00000000
--- a/examples/elements.html
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- Elements example
-
-
-
-
-
-
-
diff --git a/src/elements/constants.ts b/src/elements/constants.ts
index 31e5d6a8..23f03f96 100644
--- a/src/elements/constants.ts
+++ b/src/elements/constants.ts
@@ -5,10 +5,10 @@ const ELEMENTS_NOM_DOM_ERROR_MESSAGE =
'Tried to load BasisTheoryElements in a non-DOM environment.';
const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE =
- 'BasisTheoryElements did not load properly.';
+ 'Basis Theory Elements did not load properly.';
const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE =
- 'There was an unknown error when loading BasisTheoryElements';
+ 'There was an unknown error when loading Basis Theory Elements. Check the console for details.';
const CARD_BRANDS = [
'visa',
diff --git a/test/elements.test.ts b/test/elements.test.ts
index 913e00bf..98cabdf8 100644
--- a/test/elements.test.ts
+++ b/test/elements.test.ts
@@ -176,7 +176,7 @@ describe('Elements', () => {
loadCallback();
expect(promise).rejects.toThrow(
- 'BasisTheoryElements did not load properly.'
+ 'Basis Theory Elements did not load properly.'
);
});
@@ -185,7 +185,7 @@ describe('Elements', () => {
errorCallback();
expect(promise).rejects.toThrow(
- 'There was an unknown error when loading BasisTheoryElements'
+ 'There was an unknown error when loading Basis Theory Elements. Check the console for details.'
);
});