code-corps / code-corps/ember-stripe-service
Cannot use in (offline) tests
- Dominant language
- JavaScript
- Stars
- 91
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
In test mode (at least in environments without networking), the `` tag that this addon injects won't run and Stripe won't be defined. That means `Stripe.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
``` js
// app/services/stripe.js
function createToken (card) {
Ember.assert("Cannot create Stripe token in test environment", config.environment !== 'test');
// ...
}
// app/initializers/stripe-service.js
export function initialize() {
if (config.environment === 'test') { return; }
// ...
}
```
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.
Contributor guide
Research direction
Read app/services/stripe.js and app/initializers/stripe-service.js, then run the offline or test-mode suite to reproduce the missing Stripe failure. Done means test mode no longer fails during initialization, while attempting token creation reports the intended test-environment error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100