How do I get the stripe script loaded so Stripe is defined during my Teaspoon-Jasmine testing.
Error:
Failure/Error: ReferenceError: Stripe is not defined
Teaspoon Tests:
describe("Stripe", function() {
var paymentElement ;
describe("constructor", function(){
beforeAll(function(){
// Tried this..
var head = document.getElementsByTagName('head')[0];
var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('type', 'text/javascript');
jQueryScript.setAttribute('src', 'https://js.stripe.com/v3/');
head.appendChild(jQueryScript);
// also tried..
$.getScript( "https://js.stripe.com/v3/");
paymentElement = new Helpers.Stripe.PaymentElement();
});
describe("with defaults", function(){
it("should define stripe", function(){
expect(Stripe('test-token')).toBeDefined();
});
it("should define stripe through instance", function(){
expect(paymentElement.stripe).toBeDefined();
});
});
});
});
There's probably an asynchronous period after getScript runs but before the script is loaded and a Stripe object exists on the page.
Mocha supports asynchronous callbacks, so give that a try, something like this:
describe("constructor", function() {
before(function(done) {
$.getScript('script url here', function() {
done();
});
});
});
Recent versions of Mocha support returning promises directly, so you might also be able to do it that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With