-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use in (offline) tests #12
Comments
An alternative would be to include a version of <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
(function() {
if (typeof Stripe === 'undefined') {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'path/to/stripe.js';
head.appendChild(script);
}
}());
</script> Unfortunately, I don't know of a way to get |
Thanks @jamesarosen, we have had no issues with headless tests. Does this happen with offline tests, or it happens even when you have connection? If it's offline then, you would indeed get errors since Stripe is only meant to be included from Stripe's servers, we don't bundle the source of the library for this reason. We've thought about mocking Stripe in test environment, but have not done it yet. I may take a stab at it this week to make your life easier. |
I was seeing the problem in my headless PhantomJS tests, but not in the Chrome tests. It could have been an offline-only problem that was masked by caching in Chrome. I do develop in places without a network, though. I'm happy with any solution -- bundling, stubbing, or simply aborting the initializer -- that works in that situation. |
In the meantime, I've added import config from '../config/environment';
// The ember-stripe-service add-on relies on Stripe being
// defined. In offline mode, we won't have fetched the real
// stripe.js, so Stripe will be undefined and the add-on's
// initializer will break.
//
// See https://github.com/ride/ember-stripe-service/issues/12
export default {
name: 'fake-stripe',
before: 'stripe',
initialize: function() {
if (config.environment !== 'test') { return; }
if (typeof Stripe !== 'undefined') { return; }
window.Stripe = {
setPublishableKey: function() {},
card: { createToken: function() {} }
};
}
}; so we can continue development. I'm looking forward to seeing what you come up with :) |
Hey @jamesarosen I'll be having a look at this over the weekend, suddenly got quite busy this week. |
+1 |
@buritica I'm running into this problem as well. @jamesarosen 's |
Hey @ryanlitalien, haven't had a lot of time to dedicate to this add-on, will probably look at it over the next couple weeks. |
@buritica Thanks, subscribed :) |
@jamesarosen I've used the pattern you used in the past to fake the service out in tests (which also allows me to potentially hook into the interface to make even testing receipt of certain data testable). Do you think this needs to be part of the library or left as an implementation detail to the developer (with maybe some usage documentation explaining what to do)? |
I know some libraries will provide test support in their |
I'd suggest that the initializer should also be robust to Stripe.js failing to load. If Stripe's JS CDN goes down for whatever reason, that shouldn't also take my entire app with it. |
Any update on this? |
lol sorry, was supposed to comment. I think a possible implementation can be a follow up on #58 |
#59 adds the ability to configure mocking in testing mode. |
In test mode (at least in environments without networking), the
<script>
tag that this addon injects won't run and Stripe won't be defined. That meansStripe.setPublishableKey
won't exist and the initializer will fail.The smallest change I can think of that would work (which I've used locally successfully) is
This isn't perfect, but it's pretty good. I end up stubbing out
stripe.createToken
whenever I need to actually run that function, with without a standard stubbing library, I can't think of a good way of doing this here.The text was updated successfully, but these errors were encountered: