Skip to content

Cannot use in (offline) tests #12

@jamesarosen

Description

@jamesarosen

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 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

// 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions