-
Notifications
You must be signed in to change notification settings - Fork 40
Description
My situation
I have an app that uses this add-on to lazyLoad the Stripe API (using ENV.stripe.lazyLoad). In my tests, I want to mock the api instead of actually loading it (using ENV.stripe.mock). When using lazyLoad, I would expect both my app code to break AND my test to break if I forget to call .load() on the stripev3 service.
This seems to be consistent with the behavior described in the readme for ENV.stripe.lazyLoad
When enabled, Stripe.js will not be loaded until you call the load() function on the service.
What occurs
In tests when ENV.stripe.mock is true this add-on will run the stripev3 service's configure method in the init hook even if ENV.stripe.lazyLoad is true.
This means that even though my production app code will break if I forget to call .load(), my tests will not break because the service gets configured with the mock as soon as init runs, instead of the first time load runs.
Suggested fix
When ENV.stripe.lazyLoad is true, the stripe v3 service should only get configured in the load method, never in the init hook.
Here is the line that would need to change
https://github.com/code-corps/ember-stripe-elements/blob/develop/addon/services/stripev3.js#L41
init() {
this._super(...arguments);
let lazyLoad = this.get('lazyLoad');
let mock = this.get('mock');
// if (!lazyLoad || mock) {
if (!lazyLoad) {
this.configure();
}
},
I'm happy to PR a fix if there is agreement that what I've described here would be the correct behavior when ENV.stripe.lazyLoad and ENV.stripe.mock are both true. I'd also like to improve the documentation around using lazyLoad and add documentation for mock.