-
Notifications
You must be signed in to change notification settings - Fork 160
/
spec.js
87 lines (79 loc) · 2.22 KB
/
spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react'
import expect from 'expect'
import { shallow, mount } from 'enzyme'
import ReactStripeCheckout from './StripeCheckout.js'
const noop = () => {}
const props = {
stripeKey: 'foo',
token: noop,
name: 'foo',
description: 'foo',
image: 'foo',
ComponentClass: 'div',
panelLabel: 'foo',
amount: 100,
currency: 'USD',
locale: 'en',
email: 'foo@bar.com',
shippingAddress: false,
billingAddress: false,
zipCode: false,
alipay: false,
bitcoin: false,
allowRememberMe: false,
reconfigureOnUpdate: false,
triggerEvent: 'onClick',
className: 'StripeCheckout'
}
const mockStripeHandler = {
open() {}
}
global.StripeCheckout = {
configure() {
return mockStripeHandler
}
}
const openSpy = expect.spyOn(mockStripeHandler, 'open')
const configureSpy = expect.spyOn(StripeCheckout, 'configure').andCallThrough()
describe('<ReactStripeCheckout />', () => {
after(() => {
/* Deleting so we don't pollute global */
delete global.StripeCheckout
})
beforeEach(() => {
/* Removing function calls from previous tests */
openSpy.reset()
configureSpy.reset()
})
it('should render', () => {
const renderedComponent = shallow(
<ReactStripeCheckout {...props} />
)
expect(renderedComponent.is('button')).toEqual(true)
})
it('should render the component class it receives as children', () => {
const renderedComponent = shallow(
<ReactStripeCheckout {...props}>
<div>foo</div>
</ReactStripeCheckout>
)
expect(renderedComponent.is('div')).toEqual(true)
})
it('should pass the `stripeKey` to Stripe and configure', () => {
const renderedComponent = shallow(
<ReactStripeCheckout {...props} />
)
renderedComponent.instance().onScriptLoaded()
console.log(configureSpy.calls.length)
expect(configureSpy).toHaveBeenCalledWith({key: props.stripeKey})
})
it('should pass the `token` function to Stripe', () => {
const renderedComponent = shallow(
<ReactStripeCheckout {...props} />
)
renderedComponent.instance().onScriptLoaded()
renderedComponent.instance().showStripeDialog()
expect(openSpy).toHaveBeenCalled()
expect(openSpy.calls[0].arguments[0].token).toEqual(props.token)
})
})