3
3
* See COPYING.txt for license details.
4
4
*/
5
5
6
+ /* eslint-disable max-nested-callbacks */
6
7
define ( [
7
- 'jquery ' ,
8
- 'Magento_Paypal/js/in-context/express-checkout '
9
- ] , function ( $ , ExpressCheckout ) {
8
+ 'squire ' ,
9
+ 'jquery '
10
+ ] , function ( Squire , $ ) {
10
11
'use strict' ;
11
12
12
13
describe ( 'Magento_Paypal/js/in-context/express-checkout' , function ( ) {
13
14
14
- var model , event ;
15
+ var model ,
16
+ event ,
17
+ paypalExpressCheckout ,
18
+ injector = new Squire ( ) ,
19
+ mocks = {
20
+ 'paypalInContextExpressCheckout' : {
21
+ checkout : jasmine . createSpyObj ( 'checkout' ,
22
+ [ 'setup' , 'initXO' , 'startFlow' , 'closeFlow' ]
23
+ )
24
+ }
25
+ } ;
15
26
16
27
/**
17
28
* Run before each test method
18
29
*
19
30
* @return void
20
31
*/
21
32
beforeEach ( function ( done ) {
22
- model = new ExpressCheckout ( ) ;
23
-
24
33
event = {
25
34
/** Stub */
26
- preventDefault : function ( ) { }
35
+ preventDefault : jasmine . createSpy ( 'preventDefault' )
27
36
} ;
28
37
29
- done ( ) ;
38
+ injector . mock ( mocks ) ;
39
+
40
+ injector . require ( [
41
+ 'paypalInContextExpressCheckout' ,
42
+ 'Magento_Paypal/js/in-context/express-checkout' ] , function ( PayPal , Constr ) {
43
+ paypalExpressCheckout = PayPal ;
44
+ model = new Constr ( ) ;
45
+
46
+ done ( ) ;
47
+ } ) ;
30
48
} ) ;
31
49
32
50
describe ( 'clientConfig.click method' , function ( ) {
@@ -48,23 +66,26 @@ define([
48
66
49
67
it ( 'Check call "click" method' , function ( ) {
50
68
51
- $ . ajax = jasmine . createSpy ( ) . and . callFake ( function ( ) {
69
+ spyOn ( jQuery . fn , 'trigger' ) ;
70
+ spyOn ( jQuery , 'get' ) . and . callFake ( function ( ) {
52
71
var d = $ . Deferred ( ) ;
53
72
54
73
d . resolve ( {
55
- 'success ' : true
74
+ 'url ' : true
56
75
} ) ;
57
76
58
77
return d . promise ( ) ;
59
78
} ) ;
60
79
61
- $ . fn . trigger = jasmine . createSpy ( ) ;
62
-
63
80
model . clientConfig . click ( event ) ;
64
81
65
- expect ( $ . ajax ) . toHaveBeenCalled ( ) ;
66
- expect ( $ ( 'body' ) . trigger ) . toHaveBeenCalledWith ( 'processStop' ) ;
82
+ expect ( event . preventDefault ) . toHaveBeenCalled ( ) ;
83
+ expect ( paypalExpressCheckout . checkout . initXO ) . toHaveBeenCalled ( ) ;
67
84
expect ( model . clientConfig . checkoutInited ) . toEqual ( true ) ;
85
+ expect ( jQuery . get ) . toHaveBeenCalled ( ) ;
86
+ expect ( jQuery ( 'body' ) . trigger ) . toHaveBeenCalledWith (
87
+ jasmine . arrayContaining ( [ 'processStart' ] , [ 'processStop' ] )
88
+ ) ;
68
89
} ) ;
69
90
} ) ;
70
91
} ) ;
0 commit comments